def test_create_instance_from_bootable_volume(host): """Test to verify that a bootable volume can be created based on a Glance image Args: host(testinfra.host.Host): A hostname in dynamic_inventory.json/molecule.yml """ volume_id = helpers.get_id_by_name('volume', volume_name, host) assert volume_id is not None network_id = helpers.get_id_by_name('network', network_name, host) assert network_id is not None cmd = "{} openstack server create --volume {} --flavor {} --nic net-id={} {}'".format( utility_container, volume_id, flavor, network_id, instance_name) host.run_expect([0], cmd) instances = helpers.get_resource_list_by_name('server', host) assert instances instance_names = [x['Name'] for x in instances] assert instance_name in instance_names assert (helpers.get_expected_value('server', instance_name, 'status', 'ACTIVE', host)) assert (helpers.get_expected_value('server', instance_name, 'OS-EXT-STS:power_state', 'Running', host)) # Tear down helpers.delete_instance(instance_name, host) helpers.delete_volume(volume_name, host)
def test_create_bootable_volume(host): """Test to verify that a bootable volume can be created based on a Glance image Args: host(testinfra.host.Host): A hostname in dynamic_inventory.json/molecule.yml """ image_id = helpers.get_id_by_name('image', image_name, host) assert image_id is not None cmd = "{} openstack volume create --size 1 --image {} --bootable {}'".format( utility_container, image_id, volume_name) host.run_expect([0], cmd) assert volume_name in helpers.openstack_name_list('volume', host) assert (helpers.get_expected_value('volume', volume_name, 'status', 'available', host))
def test_create_bootable_volume(host): """Test to verify that a bootable volume can be created based on a Glance image Args: host(testinfra.host.Host): A hostname in dynamic_inventory.json/molecule.yml """ null = None false = False volume_name = 'test_volume' image_name = 'Cirros-0.3.5' zone = 'nova' image_id = helpers.get_id_by_name('image', image_name, host) data = { "volume": { "size": 1, "zone": zone, "source_volid": null, "description": null, "multiattach": false, "snapshot_id": null, "backup_id": null, "name": volume_name, "imageref": image_id, "volume_type": null, "metadata": {}, "consistencygroup_id": null } } helpers.create_bootable_volume(data, host) volumes = helpers.get_resource_list_by_name('volume', host) assert volumes volume_names = [x['Name'] for x in volumes] assert volume_name in volume_names # Tear down helpers.delete_volume(volume_name, host)
def test_assign_floating_ip_to_instance(host): """Assign floating IP to an instance/server""" # Creating an instance from image data = { "instance_name": instance_name, "from_source": 'image', "source_name": image_name, "flavor": flavor, "network_name": private_net, } helpers.create_instance(data, host) # TODO: will find out a better way to avoid implicit sleep. 'status' is 'ACTIVE' is not enough to ensure the # TODO: instance is ready, there are many instance statuses that might cause the test failed. # TODO: run `openstack server show <instance-ID> -f json` to see all the states sleep(120) # Verify the new instance is ACTIVE and Running. assert (helpers.get_expected_value('server', instance_name, 'status', 'ACTIVE', host, 20)) assert (helpers.get_expected_value('server', instance_name, 'OS-EXT-STS:power_state', 'Running', host, 20)) assert floating_ip instance_id = helpers.get_id_by_name('server', instance_name, host) assert instance_id cmd = "{} openstack server add floating ip {} {}'".format(utility_container, instance_id, floating_ip) host.run_expect([0], cmd) # After being assigned, the floating IP status should be 'ACTIVE' assert (helpers.get_expected_value('floating ip', floating_ip, 'status', 'ACTIVE', host)) # Ensure the IP can be pinged from infra1 cmd = "ping -c1 {}".format(floating_ip) assert (host.run_expect([0], cmd))
def create_floating_ip(network_name, run_on_host): """Create floating IP on a network Args: network_name (str): The name of the OpenStack network object on which the floating IP is created. run_on_host (testinfra.Host): Testinfra host object to execute the action on. Returns: str: The newly created floating ip name Raises: AssertionError: If operation is unsuccessful. """ network_id = helpers.get_id_by_name('network', network_name, run_on_host) assert network_id is not None cmd = (". ~/openrc ; " "openstack floating ip create -f json {}".format(network_id)) output = helpers.run_on_container(cmd, 'utility', run_on_host) assert (output.rc == 0) try: result = json.loads(output.stdout) except ValueError: result = output.stdout assert type(result) is dict key = None if 'name' in result.keys(): key = 'name' elif 'floating_ip_address' in result.keys(): key = 'floating_ip_address' assert key return result[key]