Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

UserData Testcase #232

Open
wants to merge 3 commits into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions eucaops/ec2ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,7 @@ def run_instance(self,
min=1,
max=1,
user_data=None,
user_data_file=None,
private_addressing=False,
username="root",
password=None,
Expand All @@ -2406,6 +2407,7 @@ def run_instance(self,
:param min: Minimum instnaces to launch, default 1
:param max: Maxiumum instances to launch, default 1
:param user_data: User-data string to pass to instance
:param user_data_file: User-data file to pass to instance
:param private_addressing: Runs an instance with only private IP address
:param username: username to use when connecting via ssh
:param password: password to use when connecting via ssh
Expand All @@ -2420,6 +2422,9 @@ def run_instance(self,
image = self.get_emi(emi=str(image))
if image is None:
raise Exception("emi is None. run_instance could not auto find an emi?")
if user_data_file:
with open(user_data_file) as userdata_file:
user_data = userdata_file.read()
if not user_data:
user_data = self.enable_root_user_data
if private_addressing is True:
Expand Down Expand Up @@ -2512,6 +2517,7 @@ def run_image(self,
max=1,
block_device_map=None,
user_data=None,
user_data_file=None,
private_addressing=False,
username="root",
password=None,
Expand All @@ -2529,6 +2535,7 @@ def run_image(self,
:param min: minimum amount of instances to try to run
:param max: max amount of instances to try to run
:param user_data: user_data to run instances with
:param user_data_file: user_data file to run instances with
:param private_addressing: boolean to run instances without public ips
:param username: username for connecting ssh to instances
:param password: password for connnecting ssh to instances
Expand All @@ -2551,6 +2558,9 @@ def run_image(self,
image = self.get_emi(emi=str(image))
if image is None:
raise Exception("emi is None. run_instance could not auto find an emi?")
if user_data_file:
with open(user_data_file) as userdata_file:
user_data = userdata_file.read()
if not user_data:
user_data = self.enable_root_user_data
if private_addressing is True:
Expand Down
5 changes: 5 additions & 0 deletions eutester/euinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,11 @@ def get_metadata(self, element_path, prefix='latest/meta-data/', timeout=10, sta
return self.sys("curl http://" + self.tester.get_ec2_ip() + ":8773/"+str(prefix) + str(element_path), code=0)
else:
raise(se)

def get_userdata(self, prefix='latest/user-data/'):
"""Return the userdata"""
element_path = ""
return self.get_metadata(element_path, prefix)

def set_block_device_prefix(self):
return self.set_rootfs_device()
Expand Down
3 changes: 3 additions & 0 deletions eutester/eutestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ def setup_parser(self,
if userdata:
parser.add_argument('--user-data',
help="User data string to provide instance run within this test", default=None)
if userdata:
parser.add_argument('--user-data-file',
help="User data file to provide instance run within this test", default=None)
if instance_user:
parser.add_argument('--instance-user',
help="Username used for ssh login. Default:'root'", default='root')
Expand Down
33 changes: 29 additions & 4 deletions testcases/cloud_user/instances/instancetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,19 @@ def __init__( self, name="InstanceBasics", credpath=None, region=None, config_fi
self.address = None
self.volume = None
self.private_addressing = False
if not user_data:
### Set userdata string to 16K to test max string size for userdata
self.user_data = self.tester.id_generator(16000)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hspencer77 I believe this change will break some test scenarios. Specifically when no user data is set we send a user data that enables root login.

if not zone:
zones = self.tester.ec2.get_all_zones()
self.zone = random.choice(zones).name
else:
self.zone = zone
self.reservation = None
self.reservation_lock = threading.Lock()
self.run_instance_params = {'image': self.image, 'user_data': user_data, 'username': instance_user,
'keypair': self.keypair.name, 'group': self.group.name, 'zone': self.zone,
'timeout': self.instance_timeout}
self.run_instance_params = {'image': self.image, 'user_data': self.user_data, 'username': instance_user,
'keypair': self.keypair.name, 'group': self.group.name,
'zone': self.zone, 'timeout': self.instance_timeout}
self.managed_network = True

### If I have access to the underlying infrastructure I can look
Expand Down Expand Up @@ -238,6 +241,28 @@ def MetaData(self):
self.set_reservation(reservation)
return reservation

def UserData(self):
"""
This case was developed to test the user-data service of an instance for consistency.
This case does a comparison of the user data passed in by the user-data argument to
the data supplied by the user-data service within the instance. Supported
user data formats can be found here: https://cloudinit.readthedocs.org/en/latest/topics/format.html
If this test fails, the test case will error out; logging the results.
The userdata tested is 16K string (maximum size of userdata string defined by AWS)
"""
if not self.reservation:
reservation = self.tester.run_instance(**self.run_instance_params)
else:
reservation = self.reservation
for instance in reservation.instances:
"""
For aesthetics, the user data value is a 16K file thats converted to string then compare,
"""
if self.user_data:
self.assertEqual(instance.get_userdata()[0], self.user_data, 'Incorrect User Data String')
self.set_reservation(reservation)
return reservation

def DNSResolveCheck(self):
"""
This case was developed to test DNS resolution information for public/private DNS
Expand Down Expand Up @@ -419,7 +444,7 @@ def ReuseAddresses(self):

### Either use the list of tests passed from config/command line to determine what subset of tests to run
test_list = testcase.args.tests or ["BasicInstanceChecks", "DNSResolveCheck", "Reboot", "MetaData", "ElasticIps",
"MultipleInstances", "LargestInstance", "PrivateIPAddressing", "Churn"]
"UserData", "MultipleInstances", "LargestInstance", "PrivateIPAddressing", "Churn"]
### Convert test suite methods to EutesterUnitTest objects
unit_list = []
for test in test_list:
Expand Down