def setUp(self): """ Setup objects required by VM instances :return: """ guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.nova = nova_utils.nova_client(self.os_creds, self.os_session) self.cinder = cinder_utils.cinder_client( self.os_creds, self.os_session) self.image_creator = None self.network_creator = None self.flavor_creator = None self.volume_creator = None self.instance_creator = None try: image_settings = openstack_tests.cirros_image_settings( name=guid + '-image', image_metadata=self.image_metadata) self.image_creator = OpenStackImage( self.os_creds, image_settings=image_settings) self.image_creator.create() network_settings = openstack_tests.get_priv_net_config( project_name=self.os_creds.project_name, net_name="{}-{}".format(guid, 'net'), subnet_name="{}-{}".format(guid, 'subnet')).network_settings self.network_creator = OpenStackNetwork( self.os_creds, network_settings) self.network_creator.create() flavor_settings = openstack_tests.get_flavor_config( name=guid + '-flavor', ram=256, disk=10, vcpus=1, metadata=self.flavor_metadata) self.flavor_creator = OpenStackFlavor( self.os_creds, flavor_settings) self.flavor_creator.create() # Create Volume volume_settings = VolumeConfig( name=self.__class__.__name__ + '-' + str(guid)) self.volume_creator = OpenStackVolume( self.os_creds, volume_settings) self.volume_creator.create(block=True) port_settings = PortConfig( name=guid + '-port', network_name=network_settings.name) instance_settings = VmInstanceConfig( name=guid + '-vm_inst', flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) self.instance_creator = OpenStackVmInstance( self.os_creds, instance_settings, image_settings) self.instance_creator.create(block=True) except: self.tearDown() raise
def test_create_flavor_all_settings(self): """ Tests the creation of an OpenStack Flavor, the deletion, then cleanup to ensure clean() does not raise any exceptions. """ # Create Flavor if self.flavor_metadata: self.flavor_metadata.update(create_flavor.MEM_PAGE_SIZE_ANY) flavor_settings = openstack_tests.get_flavor_config( name=self.flavor_name, ram=1, disk=1, vcpus=1, ephemeral=2, swap=3, rxtx_factor=2.2, is_public=False, metadata=self.flavor_metadata) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) # Delete Flavor nova_utils.delete_flavor(self.nova, flavor) self.assertIsNone( nova_utils.get_flavor_by_name(self.nova, flavor_settings.name)) # Attempt to cleanup self.flavor_creator.clean() self.assertIsNone(self.flavor_creator.get_flavor())
def setUp(self): """ Instantiates the CreateClusterTemplate object that is responsible for downloading and creating an OS template config file within OpenStack """ super(self.__class__, self).__start__() self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.cluster_type_name = self.guid + '-cluster-type' self.magnum = magnum_utils.magnum_client(self.os_creds, self.os_session) metadata = self.image_metadata if not metadata: metadata = dict() if 'extra_properties' not in metadata: metadata['extra_properties'] = dict() metadata['extra_properties']['os_distro'] = 'cirros' os_image_settings = openstack_tests.cirros_image_settings( name=self.guid + '-image', image_metadata=metadata) self.image_creator = OpenStackImage(self.os_creds, os_image_settings) flavor_config = openstack_tests.get_flavor_config( name=self.guid + '-flavor', ram=512, disk=10, vcpus=1, metadata=self.flavor_metadata) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_config) keypair_priv_filepath = 'tmp/' + self.guid keypair_pub_filepath = keypair_priv_filepath + '.pub' self.keypair_creator = OpenStackKeypair( self.os_creds, KeypairConfig(name=self.guid + '-keypair', public_filepath=keypair_pub_filepath, private_filepath=keypair_priv_filepath)) self.cluster_template_creator = None self.cluster_template_config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name) try: self.image_creator.create() self.flavor_creator.create() self.keypair_creator.create() except: self.tearDown() raise
def setUp(self): """ Setup objects required by VM instances :return: """ guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.nova = nova_utils.nova_client( self.os_creds, self.os_session) self.keystone = keystone_utils.keystone_client( self.os_creds, self.os_session) self.neutron = neutron_utils.neutron_client( self.os_creds, self.os_session) self.glance = glance_utils.glance_client( self.os_creds, self.os_session) self.image_creator = None self.network_creator = None self.flavor_creator = None self.port = None self.vm_inst = None try: image_settings = openstack_tests.cirros_image_settings( name=guid + '-image', image_metadata=self.image_metadata) self.image_creator = OpenStackImage( self.os_creds, image_settings=image_settings) self.image_creator.create() network_settings = openstack_tests.get_priv_net_config( project_name=self.os_creds.project_name, net_name="{}-{}".format(guid, 'net'), subnet_name="{}-{}".format(guid, 'subnet')).network_settings self.network_creator = OpenStackNetwork( self.os_creds, network_settings) self.network_creator.create() flavor_config = openstack_tests.get_flavor_config( name="{}-{}".format(guid, 'flavor-name'), ram=256, disk=10, vcpus=1, metadata=self.flavor_metadata) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_config) self.flavor_creator.create() port_settings = PortConfig( name=guid + '-port', network_name=network_settings.name) self.port = neutron_utils.create_port( self.neutron, self.os_creds, port_settings) self.instance_settings = VmInstanceConfig( name=guid + '-vm_inst', flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) except: self.tearDown() raise
def deploy_vnf(self): """Deploy Clearwater IMS.""" start_time = time.time() self.__logger.info("Upload VNFD") cfy_client = self.orchestrator['object'] descriptor = self.vnf['descriptor'] cfy_client.blueprints.upload( descriptor.get('file_name'), descriptor.get('name')) self.__logger.info("Get or create flavor for all clearwater vm") flavor_settings = FlavorConfig( name="{}-{}".format( self.vnf['requirements']['flavor']['name'], self.uuid), ram=self.vnf['requirements']['flavor']['ram_min'], disk=25, vcpus=2) flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings) flavor_creator.create() self.created_object.append(flavor_creator) self.vnf['inputs'].update(dict( flavor_id=flavor_settings.name, )) self.__logger.info("Create VNF Instance") cfy_client.deployments.create(descriptor.get('name'), descriptor.get('name'), self.vnf.get('inputs')) wait_for_execution(cfy_client, _get_deployment_environment_creation_execution( cfy_client, descriptor.get('name')), self.__logger, timeout=300) self.__logger.info("Start the VNF Instance deployment") execution = cfy_client.executions.start(descriptor.get('name'), 'install') # Show execution log execution = wait_for_execution( cfy_client, execution, self.__logger, timeout=3600) duration = time.time() - start_time self.__logger.info(execution) if execution.status == 'terminated': self.details['vnf'].update(status='PASS', duration=duration) self.result += 1/3 * 100 result = True else: self.details['vnf'].update(status='FAIL', duration=duration) result = False return result
def create_flavor(self, name, ram, disk, vcpus): logger.info("Creating the flavor...") flavor_settings = FlavorConfig(name=name, ram=ram, disk=disk, vcpus=vcpus) flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = flavor_creator.create() self.creators.append(flavor_creator) return flavor
def deploy_vnf(self): """Deploy ABOT-OAI-EPC.""" self.__logger.info("Upload VNFD") descriptor = self.vnf['descriptor'] self.__logger.info("Get or create flavor for all Abot-EPC") flavor_settings = FlavorConfig( name=self.vnf['requirements']['flavor']['name'], ram=self.vnf['requirements']['flavor']['ram_min'], disk=10, vcpus=1) flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings) flavor_creator.create() self.created_object.append(flavor_creator) self.__logger.info("Deploying Abot-epc bundle file ...") os.system('juju deploy {}'.format('/' + descriptor.get('file_name'))) self.__logger.info("Waiting for instances .....") status = os.system('juju-wait') self.__logger.info("juju wait completed: %s", status) self.__logger.info("Deployed Abot-epc on Openstack") nova_client = nova_utils.nova_client(self.snaps_creds) neutron_client = neutron_utils.neutron_client(self.snaps_creds) if status == 0: instances = os_utils.get_instances(nova_client) for items in instances: metadata = get_instance_metadata(nova_client, items) if 'juju-units-deployed' in metadata: sec_group = ('juju-' + metadata['juju-controller-uuid'] + '-' + metadata['juju-model-uuid']) self.sec_group_id = os_utils.get_security_group_id( neutron_client, sec_group) break self.__logger.info("Adding Security group rule....") os_utils.create_secgroup_rule( neutron_client, self.sec_group_id, 'ingress', 132) self.__logger.info("Copying the feature files to Abot_node ") os.system('juju scp -- -r {}/featureFiles abot-' 'epc-basic/0:~/'.format(self.case_dir)) self.__logger.info("Copying the feature files in Abot_node ") os.system("juju ssh abot-epc-basic/0 'sudo rsync -azvv " "~/featureFiles /etc/rebaca-test-suite" "/featureFiles'") count = 0 while count < 10: epcstatus = os.system('juju status oai-epc | ' 'grep {} | grep {} | grep {}' .format('EPC', 'is', 'running')) if epcstatus == 0: break else: time.sleep(60) count = count + 1 os.system('juju-wait') return True return False
def test_create_flavor(self): """ Tests the creation of an OpenStack flavor. """ # Create Flavor flavor_settings = FlavorConfig(name=self.flavor_name, ram=1, disk=1, vcpus=1) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor))
def run(self): """ Begins the test execution which should originate from the subclass """ self.logger.info('Begin virtual environment setup') self.start_time = time.time() self.logger.info("vPing Start Time:'%s'" % (datetime.fromtimestamp( self.start_time).strftime('%Y-%m-%d %H:%M:%S'))) image_base_name = '{}-{}'.format( CONST.__getattribute__('vping_image_name'), str(self.guid)) os_image_settings = openstack_tests.cirros_image_settings( image_base_name, image_metadata=self.cirros_image_config) self.logger.info("Creating image with name: '%s'" % image_base_name) self.image_creator = deploy_utils.create_image(self.os_creds, os_image_settings) self.creators.append(self.image_creator) private_net_name = CONST.__getattribute__( 'vping_private_net_name') + self.guid private_subnet_name = CONST.__getattribute__( 'vping_private_subnet_name') + self.guid private_subnet_cidr = CONST.__getattribute__( 'vping_private_subnet_cidr') self.logger.info("Creating network with name: '%s'" % private_net_name) self.network_creator = deploy_utils.create_network( self.os_creds, NetworkSettings(name=private_net_name, subnet_settings=[ SubnetSettings(name=private_subnet_name, cidr=private_subnet_cidr) ])) self.creators.append(self.network_creator) self.logger.info("Creating flavor with name: '%s'" % self.flavor_name) scenario = functest_utils.get_scenario() flavor_metadata = None if 'ovs' in scenario or 'fdio' in scenario: flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE flavor_creator = OpenStackFlavor( self.os_creds, FlavorSettings(name=self.flavor_name, ram=512, disk=1, vcpus=1, metadata=flavor_metadata)) flavor_creator.create() self.creators.append(flavor_creator)
def prepare_flavor(self): """Create Open Baton flavor if it doesn't exist yet""" self.logger.info( "Create Flavor for Open Baton NFVO if not yet existing") flavor_settings = FlavorSettings( name=self.mano['requirements']['flavor']['name'], ram=self.mano['requirements']['flavor']['ram_min'], disk=self.mano['requirements']['flavor']['disk'], vcpus=self.mano['requirements']['flavor']['vcpus']) flavor = OpenStackFlavor(self.snaps_creds, flavor_settings) flavor_info = flavor.create() self.created_resources.append(flavor) self.mano['details']['flavor'] = {} self.mano['details']['flavor']['name'] = flavor_settings.name self.mano['details']['flavor']['id'] = flavor_info.id
def test_create_flavor_existing(self): """ Tests the creation of an OpenStack flavor then starts another creator to ensure it has not been done twice. """ # Create Flavor flavor_settings = FlavorConfig(name=self.flavor_name, ram=1, disk=1, vcpus=1) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) flavor_creator_2 = OpenStackFlavor(self.os_creds, flavor_settings) flavor2 = flavor_creator_2.create() self.assertEqual(flavor.id, flavor2.id)
def _create_flavor(self, name): """Create flavor for tests.""" scenario = CONST.__getattribute__('DEPLOY_SCENARIO') flavor_metadata = None if 'ovs' in scenario or 'fdio' in scenario: flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE flavor_creator = OpenStackFlavor( self.os_creds, FlavorConfig( name=name, ram=CONST.__getattribute__('openstack_flavor_ram'), disk=CONST.__getattribute__('openstack_flavor_disk'), vcpus=CONST.__getattribute__('openstack_flavor_vcpus'), metadata=flavor_metadata)) flavor = flavor_creator.create() if flavor is None: raise Exception('Failed to create flavor') self.creators.append(flavor_creator) return flavor.id
def test_create_clean_flavor(self): """ Tests the creation and cleanup of an OpenStack flavor. """ # Create Flavor flavor_settings = FlavorConfig(name=self.flavor_name, ram=1, disk=1, vcpus=1) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) # Clean Flavor self.flavor_creator.clean() self.assertIsNone(self.flavor_creator.get_flavor()) self.assertIsNone( nova_utils.get_flavor_by_name(self.nova, flavor_settings.name))
def setUp(self): """ Instantiates OpenStack instances that cannot be spawned by Heat """ guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) stack_name1 = guid + '-stack1' stack_name2 = guid + '-stack2' self.network_name = guid + '-net' self.subnet_name = guid + '-subnet' self.vm_inst_name = guid + '-inst' self.image_creator = OpenStackImage( self.os_creds, openstack_tests.cirros_image_settings( name=guid + '-image', image_metadata=self.image_metadata)) self.image_creator.create() # Create Flavor self.flavor_creator = OpenStackFlavor( self.os_creds, FlavorConfig(name=guid + '-flavor', ram=256, disk=10, vcpus=1)) self.flavor_creator.create() env_values = { 'image_name': self.image_creator.image_settings.name, 'flavor_name': self.flavor_creator.flavor_settings.name, 'net_name': self.network_name, 'subnet_name': self.subnet_name, 'inst_name': self.vm_inst_name } heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'test_heat_template.yaml') self.stack_settings1 = StackConfig(name=stack_name1, template_path=heat_tmplt_path, env_values=env_values) self.stack_settings2 = StackConfig(name=stack_name2, template_path=heat_tmplt_path, env_values=env_values) self.stack1 = None self.stack2 = None self.heat_client = heat_utils.heat_client(self.os_creds, self.os_session)
def setUp(self): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.cluster_type_name = self.guid + '-cluster-type' self.magnum = magnum_utils.magnum_client( self.os_creds, self.os_session) metadata = self.image_metadata if not metadata: metadata = dict() if 'extra_properties' not in metadata: metadata['extra_properties'] = dict() metadata['extra_properties']['os_distro'] = 'cirros' os_image_settings = openstack_tests.cirros_image_settings( name=self.guid + '-image', image_metadata=metadata) self.image_creator = OpenStackImage(self.os_creds, os_image_settings) self.flavor_creator = OpenStackFlavor( self.os_creds, FlavorConfig( name=self.guid + '-flavor', ram=512, disk=10, vcpus=1)) keypair_priv_filepath = 'tmp/' + self.guid keypair_pub_filepath = keypair_priv_filepath + '.pub' self.keypair_creator = OpenStackKeypair( self.os_creds, KeypairConfig( name=self.guid + '-keypair', public_filepath=keypair_pub_filepath, private_filepath=keypair_priv_filepath)) self.cluster_template = None try: self.image_creator.create() self.flavor_creator.create() self.keypair_creator.create() except: self.tearDown() raise
def get_flavor_creators(self): """ Returns a list of Flavor creator objects as configured by the heat template :return: list() of OpenStackFlavor objects """ out = list() flavors = heat_utils.get_stack_flavors(self.__heat_cli, self.__nova, self.__stack) for flavor in flavors: settings = settings_utils.create_flavor_config(flavor) creator = OpenStackFlavor(self._os_creds, settings) out.append(creator) try: creator.initialize() except Exception as e: logger.error( 'Unexpected error initializing volume creator - %s', e) return out
def test_create_delete_flavor(self): """ Tests the creation of an OpenStack Flavor, the deletion, then cleanup to ensure clean() does not raise any exceptions. """ # Create Flavor flavor_settings = FlavorConfig(name=self.flavor_name, ram=1, disk=1, vcpus=1) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) # Delete Flavor nova_utils.delete_flavor(self.nova, flavor) self.assertIsNone( nova_utils.get_flavor_by_name(self.nova, flavor_settings.name)) # Attempt to cleanup self.flavor_creator.clean() self.assertIsNone(self.flavor_creator.get_flavor())
class CreateClusterTemplateTests(OSIntegrationTestCase): """ Test for the OpenStackClusterTemplate class defined in py without any QoS Specs or Encryption """ def setUp(self): """ Instantiates the CreateClusterTemplate object that is responsible for downloading and creating an OS template config file within OpenStack """ super(self.__class__, self).__start__() self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.cluster_type_name = self.guid + '-cluster-type' self.magnum = magnum_utils.magnum_client(self.os_creds, self.os_session) metadata = self.image_metadata if not metadata: metadata = dict() if 'extra_properties' not in metadata: metadata['extra_properties'] = dict() metadata['extra_properties']['os_distro'] = 'cirros' os_image_settings = openstack_tests.cirros_image_settings( name=self.guid + '-image', image_metadata=metadata) self.image_creator = OpenStackImage(self.os_creds, os_image_settings) flavor_config = openstack_tests.get_flavor_config( name=self.guid + '-flavor', ram=512, disk=10, vcpus=1, metadata=self.flavor_metadata) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_config) keypair_priv_filepath = 'tmp/' + self.guid keypair_pub_filepath = keypair_priv_filepath + '.pub' self.keypair_creator = OpenStackKeypair( self.os_creds, KeypairConfig(name=self.guid + '-keypair', public_filepath=keypair_pub_filepath, private_filepath=keypair_priv_filepath)) self.cluster_template_creator = None self.cluster_template_config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name) try: self.image_creator.create() self.flavor_creator.create() self.keypair_creator.create() except: self.tearDown() raise def tearDown(self): """ Cleans the template config """ if self.cluster_template_creator: try: self.cluster_template_creator.clean() except: pass if self.keypair_creator: try: self.keypair_creator.clean() except: pass if self.flavor_creator: try: self.flavor_creator.clean() except: pass if self.image_creator: try: self.image_creator.clean() except: pass super(self.__class__, self).__clean__() def test_create_cluster_template(self): """ Tests the creation of an OpenStack cluster template. """ # Create ClusterTemplate self.cluster_template_creator = OpenStackClusterTemplate( self.os_creds, self.cluster_template_config) created_cluster_template = self.cluster_template_creator.create() self.assertIsNotNone(created_cluster_template) self.assertEqual(self.cluster_template_config.name, created_cluster_template.name) retrieved_cluster_template1 = magnum_utils.get_cluster_template( self.magnum, template_config=self.cluster_template_config) self.assertIsNotNone(retrieved_cluster_template1) self.assertEqual(created_cluster_template, retrieved_cluster_template1) retrieved_cluster_template2 = magnum_utils.get_cluster_template_by_id( self.magnum, created_cluster_template.id) self.assertEqual(created_cluster_template, retrieved_cluster_template2) def test_create_delete_cluster_template(self): """ Tests the creation then deletion of an OpenStack template config to ensure clean() does not raise an Exception. """ # Create ClusterTemplate self.cluster_template_creator = OpenStackClusterTemplate( self.os_creds, self.cluster_template_config) created_cluster_template = self.cluster_template_creator.create() self.assertIsNotNone(created_cluster_template) self.cluster_template_creator.clean() tmplt = magnum_utils.get_cluster_template( self.magnum, template_name=self.cluster_template_config.name) self.assertIsNone(tmplt) def test_create_same_cluster_template(self): """ Tests the creation of an OpenStack cluster_template when one already exists. """ # Create ClusterTemplate self.cluster_template_creator = OpenStackClusterTemplate( self.os_creds, self.cluster_template_config) cluster_template1 = self.cluster_template_creator.create() retrieved_cluster_template = magnum_utils.get_cluster_template( self.magnum, template_config=self.cluster_template_config) self.assertEqual(cluster_template1, retrieved_cluster_template) # Should be retrieving the instance data os_cluster_template_2 = OpenStackClusterTemplate( self.os_creds, self.cluster_template_config) cluster_template2 = os_cluster_template_2.create() self.assertEqual(cluster_template2, cluster_template2) def test_create_cluster_template_bad_flavor(self): """ Tests the creation of an OpenStack cluster template raises an exception with an invalid flavor. """ # Create ClusterTemplate cluster_template_config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor='foo') self.cluster_template_creator = OpenStackClusterTemplate( self.os_creds, cluster_template_config) with self.assertRaises(BadRequest): self.cluster_template_creator.create() def test_create_cluster_template_bad_master_flavor(self): """ Tests the creation of an OpenStack cluster template raises an exception with an invalid master flavor. """ # Create ClusterTemplate cluster_template_config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name, master_flavor='foo') self.cluster_template_creator = OpenStackClusterTemplate( self.os_creds, cluster_template_config) with self.assertRaises(BadRequest): self.cluster_template_creator.create() def test_create_cluster_template_bad_image(self): """ Tests the creation of an OpenStack cluster template raises an exception with an invalid image. """ # Create ClusterTemplate cluster_template_config = ClusterTemplateConfig( name=self.cluster_type_name, image='foo', keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name) self.cluster_template_creator = OpenStackClusterTemplate( self.os_creds, cluster_template_config) with self.assertRaises(BadRequest): self.cluster_template_creator.create() def test_create_cluster_template_bad_network_driver(self): """ Tests the creation of an OpenStack cluster template raises an exception with an invalid keypair. """ # Create ClusterTemplate cluster_template_config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name, network_driver='foo') self.cluster_template_creator = OpenStackClusterTemplate( self.os_creds, cluster_template_config) with self.assertRaises(BadRequest): self.cluster_template_creator.create() def test_create_cluster_template_bad_volume_driver(self): """ Tests the creation of an OpenStack cluster template raises an exception with an invalid keypair. """ # Create ClusterTemplate cluster_template_config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name, volume_driver='foo') self.cluster_template_creator = OpenStackClusterTemplate( self.os_creds, cluster_template_config) with self.assertRaises(BadRequest): self.cluster_template_creator.create()
class HeatUtilsCreateSimpleStackTests(OSComponentTestCase): """ Test basic Heat functionality """ def setUp(self): """ Instantiates OpenStack instances that cannot be spawned by Heat """ guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) stack_name1 = guid + '-stack1' stack_name2 = guid + '-stack2' self.network_name = guid + '-net' self.subnet_name = guid + '-subnet' self.vm_inst_name = guid + '-inst' self.image_creator = OpenStackImage( self.os_creds, openstack_tests.cirros_image_settings( name=guid + '-image', image_metadata=self.image_metadata)) self.image_creator.create() # Create Flavor self.flavor_creator = OpenStackFlavor( self.os_creds, FlavorConfig(name=guid + '-flavor', ram=256, disk=10, vcpus=1)) self.flavor_creator.create() env_values = { 'image_name': self.image_creator.image_settings.name, 'flavor_name': self.flavor_creator.flavor_settings.name, 'net_name': self.network_name, 'subnet_name': self.subnet_name, 'inst_name': self.vm_inst_name } heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'test_heat_template.yaml') self.stack_settings1 = StackConfig(name=stack_name1, template_path=heat_tmplt_path, env_values=env_values) self.stack_settings2 = StackConfig(name=stack_name2, template_path=heat_tmplt_path, env_values=env_values) self.stack1 = None self.stack2 = None self.heat_client = heat_utils.heat_client(self.os_creds, self.os_session) def tearDown(self): """ Cleans the stack and image """ if self.stack1: try: heat_utils.delete_stack(self.heat_client, self.stack1) except: pass if self.stack2: try: heat_utils.delete_stack(self.heat_client, self.stack2) except: pass if self.image_creator: try: self.image_creator.clean() except: pass if self.flavor_creator: try: self.flavor_creator.clean() except: pass super(self.__class__, self).__clean__() def test_create_stack(self): """ Tests the creation of an OpenStack Heat stack1 that does not exist. """ self.stack1 = heat_utils.create_stack(self.heat_client, self.stack_settings1) stack_query_1 = heat_utils.get_stack( self.heat_client, stack_settings=self.stack_settings1) self.assertEqual(self.stack1, stack_query_1) stack_query_2 = heat_utils.get_stack( self.heat_client, stack_name=self.stack_settings1.name) self.assertEqual(self.stack1, stack_query_2) stack_query_3 = heat_utils.get_stack_by_id(self.heat_client, self.stack1.id) self.assertEqual(self.stack1, stack_query_3) resources = heat_utils.get_resources(self.heat_client, self.stack1.id) self.assertIsNotNone(resources) self.assertEqual(4, len(resources)) outputs = heat_utils.get_outputs(self.heat_client, self.stack1) self.assertIsNotNone(outputs) self.assertEqual(0, len(outputs)) self.assertTrue(stack_active(self.heat_client, self.stack1)) neutron = neutron_utils.neutron_client(self.os_creds, self.os_session) networks = heat_utils.get_stack_networks(self.heat_client, neutron, self.stack1) self.assertIsNotNone(networks) self.assertEqual(1, len(networks)) self.assertEqual(self.network_name, networks[0].name) subnets = neutron_utils.get_subnets_by_network(neutron, networks[0]) self.assertEqual(1, len(subnets)) self.assertEqual(self.subnet_name, subnets[0].name) nova = nova_utils.nova_client(self.os_creds, self.os_session) keystone = keystone_utils.keystone_client(self.os_creds, self.os_session) servers = heat_utils.get_stack_servers(self.heat_client, nova, neutron, keystone, self.stack1, self.os_creds.project_name) self.assertIsNotNone(servers) self.assertEqual(1, len(servers)) self.assertEqual(self.vm_inst_name, servers[0].name) def test_create_stack_x2(self): """ Tests the creation of an OpenStack keypair that does not exist. """ self.stack1 = heat_utils.create_stack(self.heat_client, self.stack_settings1) stack1_query_1 = heat_utils.get_stack( self.heat_client, stack_settings=self.stack_settings1) self.assertEqual(self.stack1, stack1_query_1) stack1_query_2 = heat_utils.get_stack( self.heat_client, stack_name=self.stack_settings1.name) self.assertEqual(self.stack1, stack1_query_2) stack1_query_3 = heat_utils.get_stack_by_id(self.heat_client, self.stack1.id) self.assertEqual(self.stack1, stack1_query_3) self.assertTrue(stack_active(self.heat_client, self.stack1)) self.stack2 = heat_utils.create_stack(self.heat_client, self.stack_settings2) stack2_query_1 = heat_utils.get_stack( self.heat_client, stack_settings=self.stack_settings2) self.assertEqual(self.stack2, stack2_query_1) stack2_query_2 = heat_utils.get_stack( self.heat_client, stack_name=self.stack_settings2.name) self.assertEqual(self.stack2, stack2_query_2) stack2_query_3 = heat_utils.get_stack_by_id(self.heat_client, self.stack2.id) self.assertEqual(self.stack2, stack2_query_3) self.assertTrue(stack_active(self.heat_client, self.stack2))
def deploy_orchestrator(self): # pylint: disable=too-many-locals """ Create network, subnet, router Bootstrap juju """ self.__logger.info("Deployed Orchestrator") private_net_name = getattr( CONST, 'vnf_{}_private_net_name'.format(self.case_name)) private_subnet_name = getattr( CONST, 'vnf_{}_private_subnet_name'.format(self.case_name)) private_subnet_cidr = getattr( CONST, 'vnf_{}_private_subnet_cidr'.format(self.case_name)) abot_router = getattr( CONST, 'vnf_{}_external_router'.format(self.case_name)) self.__logger.info("Creating full network ...") subnet_settings = SubnetConfig( name=private_subnet_name, cidr=private_subnet_cidr) network_settings = NetworkConfig( name=private_net_name, subnet_settings=[subnet_settings]) network_creator = OpenStackNetwork(self.snaps_creds, network_settings) net_id = network_creator.create().id self.created_object.append(network_creator) ext_net_name = snaps_utils.get_ext_net_name(self.snaps_creds) self.__logger.info("Creating network Router ....") router_creator = OpenStackRouter( self.snaps_creds, RouterConfig( name=abot_router, external_gateway=ext_net_name, internal_subnets=[subnet_settings.name])) router_creator.create() self.created_object.append(router_creator) self.__logger.info("Creating Flavor ....") flavor_settings = FlavorConfig( name=self.orchestrator['requirements']['flavor']['name'], ram=self.orchestrator['requirements']['flavor']['ram_min'], disk=10, vcpus=1) flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings) flavor_creator.create() self.created_object.append(flavor_creator) self.__logger.info("Upload some OS images if it doesn't exist") images = get_config("tenant_images", self.config_file) self.__logger.info("Images needed for vEPC: %s", images) for image_name, image_file in images.iteritems(): self.__logger.info("image: %s, file: %s", image_name, image_file) if image_file and image_name: image_creator = OpenStackImage(self.snaps_creds, ImageConfig( name=image_name, image_user='******', img_format='qcow2', image_file=image_file)) image_id = image_creator.create().id os.system( 'juju metadata generate-image -d ~ -i {} -s {} -r ' '{} -u {}'.format( image_id, image_name, os.environ.get( "OS_REGION_NAME", self.default_region_name), self.public_auth_url)) self.created_object.append(image_creator) self.__logger.info("Credential information : %s", net_id) juju_bootstrap_command = ( 'juju bootstrap abot-epc abot-controller --config network={} ' '--metadata-source ~ --config ssl-hostname-verification=false ' '--constraints mem=2G --bootstrap-series xenial ' '--config use-floating-ip=true --debug ' '--config use-default-secgroup=true'.format(net_id)) os.system(juju_bootstrap_command) return True
class CreateFlavorTests(OSComponentTestCase): """ Test for the CreateSecurityGroup class defined in create_security_group.py """ def setUp(self): """ Instantiates the CreateSecurityGroup object that is responsible for downloading and creating an OS image file within OpenStack """ guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.flavor_name = guid + 'name' self.nova = nova_utils.nova_client(self.os_creds, self.os_session) # Initialize for cleanup self.flavor_creator = None def tearDown(self): """ Cleans the image and downloaded image file """ if self.flavor_creator: self.flavor_creator.clean() super(self.__class__, self).__clean__() def test_create_flavor(self): """ Tests the creation of an OpenStack flavor. """ # Create Flavor flavor_settings = FlavorConfig(name=self.flavor_name, ram=1, disk=1, vcpus=1) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) def test_create_flavor_existing(self): """ Tests the creation of an OpenStack flavor then starts another creator to ensure it has not been done twice. """ # Create Flavor flavor_settings = FlavorConfig(name=self.flavor_name, ram=1, disk=1, vcpus=1) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) flavor_creator_2 = OpenStackFlavor(self.os_creds, flavor_settings) flavor2 = flavor_creator_2.create() self.assertEqual(flavor.id, flavor2.id) def test_create_clean_flavor(self): """ Tests the creation and cleanup of an OpenStack flavor. """ # Create Flavor flavor_settings = FlavorConfig(name=self.flavor_name, ram=1, disk=1, vcpus=1) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) # Clean Flavor self.flavor_creator.clean() self.assertIsNone(self.flavor_creator.get_flavor()) self.assertIsNone( nova_utils.get_flavor_by_name(self.nova, flavor_settings.name)) def test_create_delete_flavor(self): """ Tests the creation of an OpenStack Flavor, the deletion, then cleanup to ensure clean() does not raise any exceptions. """ # Create Flavor flavor_settings = FlavorConfig(name=self.flavor_name, ram=1, disk=1, vcpus=1) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) # Delete Flavor nova_utils.delete_flavor(self.nova, flavor) self.assertIsNone( nova_utils.get_flavor_by_name(self.nova, flavor_settings.name)) # Attempt to cleanup self.flavor_creator.clean() self.assertIsNone(self.flavor_creator.get_flavor()) def test_create_flavor_all_settings(self): """ Tests the creation of an OpenStack Flavor, the deletion, then cleanup to ensure clean() does not raise any exceptions. """ # Create Flavor if self.flavor_metadata: self.flavor_metadata.update(create_flavor.MEM_PAGE_SIZE_ANY) flavor_settings = openstack_tests.get_flavor_config( name=self.flavor_name, ram=1, disk=1, vcpus=1, ephemeral=2, swap=3, rxtx_factor=2.2, is_public=False, metadata=self.flavor_metadata) self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_settings) flavor = self.flavor_creator.create() self.assertTrue(validate_flavor(self.nova, flavor_settings, flavor)) # Delete Flavor nova_utils.delete_flavor(self.nova, flavor) self.assertIsNone( nova_utils.get_flavor_by_name(self.nova, flavor_settings.name)) # Attempt to cleanup self.flavor_creator.clean() self.assertIsNone(self.flavor_creator.get_flavor())
def create(self, use_custom_images=False, use_custom_flavors=False, create_project=False): if create_project: logger.debug("Creating project (tenant) for Tempest suite") project_name = CONST.__getattribute__( 'tempest_identity_tenant_name') + self.guid project_creator = deploy_utils.create_project( self.os_creds, ProjectConfig(name=project_name, description=CONST.__getattribute__( 'tempest_identity_tenant_description'))) if (project_creator is None or project_creator.get_project() is None): raise Exception("Failed to create tenant") project_id = project_creator.get_project().id self.creators.append(project_creator) logger.debug("Creating user for Tempest suite") user_creator = deploy_utils.create_user( self.os_creds, UserConfig( name=CONST.__getattribute__('tempest_identity_user_name') + self.guid, password=CONST.__getattribute__( 'tempest_identity_user_password'), project_name=project_name)) if user_creator is None or user_creator.get_user() is None: raise Exception("Failed to create user") user_id = user_creator.get_user().id self.creators.append(user_creator) else: project_name = None project_id = None user_id = None logger.debug("Creating private network for Tempest suite") network_creator = deploy_utils.create_network( self.os_creds, NetworkConfig( name=CONST.__getattribute__('tempest_private_net_name') + self.guid, project_name=project_name, subnet_settings=[ SubnetConfig(name=CONST.__getattribute__( 'tempest_private_subnet_name') + self.guid, cidr=CONST.__getattribute__( 'tempest_private_subnet_cidr')) ])) if network_creator is None or network_creator.get_network() is None: raise Exception("Failed to create private network") self.creators.append(network_creator) image_id = None image_id_alt = None flavor_id = None flavor_id_alt = None logger.debug("Creating image for Tempest suite") image_base_name = CONST.__getattribute__( 'openstack_image_name') + self.guid os_image_settings = openstack_tests.cirros_image_settings( image_base_name, public=True, image_metadata=self.cirros_image_config) logger.debug("Creating image for Tempest suite") image_creator = deploy_utils.create_image(self.os_creds, os_image_settings) if image_creator is None: raise Exception('Failed to create image') self.creators.append(image_creator) image_id = image_creator.get_image().id if use_custom_images: logger.debug("Creating 2nd image for Tempest suite") image_base_name_alt = CONST.__getattribute__( 'openstack_image_name_alt') + self.guid os_image_settings_alt = openstack_tests.cirros_image_settings( image_base_name_alt, public=True, image_metadata=self.cirros_image_config) logger.debug("Creating 2nd image for Tempest suite") image_creator_alt = deploy_utils.create_image( self.os_creds, os_image_settings_alt) if image_creator_alt is None: raise Exception('Failed to create image') self.creators.append(image_creator_alt) image_id_alt = image_creator_alt.get_image().id if (CONST.__getattribute__('tempest_use_custom_flavors') == 'True' or use_custom_flavors): logger.info("Creating flavor for Tempest suite") scenario = CONST.__getattribute__('DEPLOY_SCENARIO') flavor_metadata = None if 'ovs' in scenario or 'fdio' in scenario: flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE flavor_creator = OpenStackFlavor( self.os_creds, FlavorConfig( name=CONST.__getattribute__('openstack_flavor_name') + self.guid, ram=CONST.__getattribute__('openstack_flavor_ram'), disk=CONST.__getattribute__('openstack_flavor_disk'), vcpus=CONST.__getattribute__('openstack_flavor_vcpus'), metadata=flavor_metadata)) flavor = flavor_creator.create() if flavor is None: raise Exception('Failed to create flavor') self.creators.append(flavor_creator) flavor_id = flavor.id if use_custom_flavors: logger.info("Creating 2nd flavor for Tempest suite") scenario = CONST.__getattribute__('DEPLOY_SCENARIO') flavor_metadata_alt = None if 'ovs' in scenario or 'fdio' in scenario: flavor_metadata_alt = create_flavor.MEM_PAGE_SIZE_LARGE CONST.__setattr__('openstack_flavor_ram', 1024) flavor_creator_alt = OpenStackFlavor( self.os_creds, FlavorConfig( name=CONST.__getattribute__('openstack_flavor_name_alt') + self.guid, ram=CONST.__getattribute__('openstack_flavor_ram'), disk=CONST.__getattribute__('openstack_flavor_disk'), vcpus=CONST.__getattribute__('openstack_flavor_vcpus'), metadata=flavor_metadata_alt)) flavor_alt = flavor_creator_alt.create() if flavor_alt is None: raise Exception('Failed to create flavor') self.creators.append(flavor_creator_alt) flavor_id_alt = flavor_alt.id print("RESOURCES CREATE: image_id: %s, image_id_alt: %s, " "flavor_id: %s, flavor_id_alt: %s" % ( image_id, image_id_alt, flavor_id, flavor_id_alt, )) result = { 'image_id': image_id, 'image_id_alt': image_id_alt, 'flavor_id': flavor_id, 'flavor_id_alt': flavor_id_alt } if create_project: result['project_id'] = project_id result['tenant_id'] = project_id # for compatibility result['user_id'] = user_id return result
def deploy_vnf(self): start_time = time.time() self.logger.info("Deploying %s...", self.vnf['name']) main_agent = MainAgent(nfvo_ip=self.mano['details']['fip'].ip, nfvo_port=8080, https=False, version=1, username=self.mano['credentials']['username'], password=self.mano['credentials']['password']) self.logger.info("Create %s Flavor if not existing", self.vnf['name']) flavor_settings = FlavorSettings( name=self.vnf['requirements']['flavor']['name'], ram=self.vnf['requirements']['flavor']['ram_min'], disk=self.vnf['requirements']['flavor']['disk'], vcpus=self.vnf['requirements']['flavor']['vcpus']) flavor = OpenStackFlavor(self.snaps_creds, flavor_settings) flavor_info = flavor.create() self.logger.debug("Flavor id: %s", flavor_info.id) self.logger.info("Getting project 'default'...") project_agent = main_agent.get_agent("project", "") for project in json.loads(project_agent.find()): if project.get("name") == "default": self.mano['details']['project_id'] = project.get("id") self.logger.info("Found project 'default': %s", project) break vim_json = self.get_vim_descriptor() self.logger.info("Registering VIM: %s", vim_json) main_agent.get_agent( "vim", project_id=self.mano['details']['project_id']).create( entity=json.dumps(vim_json)) market_agent = main_agent.get_agent( "market", project_id=self.mano['details']['project_id']) try: self.logger.info("sending: %s", self.vnf['descriptor']['url']) nsd = market_agent.create(entity=self.vnf['descriptor']['url']) if nsd.get('id') is None: self.logger.error("NSD not onboarded correctly") duration = time.time() - start_time self.details["vnf"].update(status='FAIL', duration=duration) return False self.mano['details']['nsd_id'] = nsd.get('id') self.logger.info("Onboarded NSD: " + nsd.get("name")) nsr_agent = main_agent.get_agent( "nsr", project_id=self.mano['details']['project_id']) self.mano['details']['nsr'] = nsr_agent.create( self.mano['details']['nsd_id']) except NfvoException as exc: self.logger.error(exc.message) duration = time.time() - start_time self.details["vnf"].update(status='FAIL', duration=duration) return False if self.mano['details']['nsr'].get('code') is not None: self.logger.error("%s cannot be deployed: %s -> %s", self.vnf['name'], self.mano['details']['nsr'].get('code'), self.mano['details']['nsr'].get('message')) self.logger.error("%s cannot be deployed", self.vnf['name']) duration = time.time() - start_time self.details["vnf"].update(status='FAIL', duration=duration) return False timeout = 0 self.logger.info("Waiting for NSR to go to ACTIVE...") while self.mano['details']['nsr'].get("status") != 'ACTIVE' \ and self.mano['details']['nsr'].get("status") != 'ERROR': timeout += 1 self.logger.info("NSR is not yet ACTIVE... (%ss)", 5 * timeout) if timeout == 300: self.logger.error("INACTIVE NSR after %s sec..", 5 * timeout) duration = time.time() - start_time self.details["vnf"].update(status='FAIL', duration=duration) return False time.sleep(5) self.mano['details']['nsr'] = json.loads( nsr_agent.find(self.mano['details']['nsr'].get('id'))) duration = time.time() - start_time if self.mano['details']['nsr'].get("status") == 'ACTIVE': self.details["vnf"].update(status='PASS', duration=duration) self.logger.info("Sleep for 60s to ensure that all " "services are up and running...") time.sleep(60) result = True else: self.details["vnf"].update(status='FAIL', duration=duration) self.logger.error("NSR: %s", self.mano['details'].get('nsr')) result = False return result
def deploy_orchestrator(self): """ Deploy Cloudify Manager. network, security group, fip, VM creation """ # network creation start_time = time.time() self.__logger.info("Creating keypair ...") kp_file = os.path.join(self.data_dir, "cloudify_vrouter.pem") keypair_settings = KeypairSettings(name='cloudify_vrouter_kp', private_filepath=kp_file) keypair_creator = OpenStackKeypair(self.snaps_creds, keypair_settings) keypair_creator.create() self.created_object.append(keypair_creator) self.__logger.info("Creating full network ...") subnet_settings = SubnetSettings(name='cloudify_vrouter_subnet', cidr='10.67.79.0/24') network_settings = NetworkSettings(name='cloudify_vrouter_network', subnet_settings=[subnet_settings]) network_creator = OpenStackNetwork(self.snaps_creds, network_settings) network_creator.create() self.created_object.append(network_creator) ext_net_name = snaps_utils.get_ext_net_name(self.snaps_creds) router_creator = OpenStackRouter( self.snaps_creds, RouterSettings(name='cloudify_vrouter_router', external_gateway=ext_net_name, internal_subnets=[subnet_settings.name])) router_creator.create() self.created_object.append(router_creator) # security group creation self.__logger.info("Creating security group for cloudify manager vm") sg_rules = list() sg_rules.append( SecurityGroupRuleSettings(sec_grp_name="sg-cloudify-manager", direction=Direction.ingress, protocol=Protocol.tcp, port_range_min=1, port_range_max=65535)) sg_rules.append( SecurityGroupRuleSettings(sec_grp_name="sg-cloudify-manager", direction=Direction.ingress, protocol=Protocol.udp, port_range_min=1, port_range_max=65535)) security_group_creator = OpenStackSecurityGroup( self.snaps_creds, SecurityGroupSettings(name="sg-cloudify-manager", rule_settings=sg_rules)) security_group_creator.create() self.created_object.append(security_group_creator) # orchestrator VM flavor self.__logger.info("Get or create flavor for cloudify manager vm ...") flavor_settings = FlavorSettings( name=self.orchestrator['requirements']['flavor']['name'], ram=self.orchestrator['requirements']['flavor']['ram_min'], disk=50, vcpus=2) flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings) flavor_creator.create() self.created_object.append(flavor_creator) image_settings = ImageSettings( name=self.orchestrator['requirements']['os_image'], image_user='******', exists=True) port_settings = PortSettings(name='cloudify_manager_port', network_name=network_settings.name) manager_settings = VmInstanceSettings( name='cloudify_manager', flavor=flavor_settings.name, port_settings=[port_settings], security_group_names=[ security_group_creator.sec_grp_settings.name ], floating_ip_settings=[ FloatingIpSettings( name='cloudify_manager_fip', port_name=port_settings.name, router_name=router_creator.router_settings.name) ]) manager_creator = OpenStackVmInstance(self.snaps_creds, manager_settings, image_settings, keypair_settings) self.__logger.info("Creating cloudify manager VM") manager_creator.create() self.created_object.append(manager_creator) public_auth_url = os_utils.get_endpoint('identity') self.__logger.info("Set creds for cloudify manager") cfy_creds = dict(keystone_username=self.tenant_name, keystone_password=self.tenant_name, keystone_tenant_name=self.tenant_name, keystone_url=public_auth_url) cfy_client = CloudifyClient(host=manager_creator.get_floating_ip().ip, username='******', password='******', tenant='default_tenant') self.orchestrator['object'] = cfy_client self.cfy_manager_ip = manager_creator.get_floating_ip().ip self.__logger.info("Attemps running status of the Manager") cfy_status = None retry = 10 while str(cfy_status) != 'running' and retry: try: cfy_status = cfy_client.manager.get_status()['status'] self.__logger.debug("The current manager status is %s", cfy_status) except Exception: # pylint: disable=broad-except self.__logger.warning("Cloudify Manager isn't " + "up and running. Retrying ...") retry = retry - 1 time.sleep(30) if str(cfy_status) == 'running': self.__logger.info("Cloudify Manager is up and running") else: raise Exception("Cloudify Manager isn't up and running") self.__logger.info("Put OpenStack creds in manager") secrets_list = cfy_client.secrets.list() for k, val in cfy_creds.iteritems(): if not any(d.get('key', None) == k for d in secrets_list): cfy_client.secrets.create(k, val) else: cfy_client.secrets.update(k, val) duration = time.time() - start_time self.__logger.info("Put private keypair in manager") if manager_creator.vm_ssh_active(block=True): ssh = manager_creator.ssh_client() scp = SCPClient(ssh.get_transport(), socket_timeout=15.0) scp.put(kp_file, '~/') cmd = "sudo cp ~/cloudify_vrouter.pem /etc/cloudify/" run_blocking_ssh_command(ssh, cmd) cmd = "sudo chmod 444 /etc/cloudify/cloudify_vrouter.pem" run_blocking_ssh_command(ssh, cmd) cmd = "sudo yum install -y gcc python-devel" run_blocking_ssh_command(ssh, cmd, "Unable to install packages on manager") self.details['orchestrator'].update(status='PASS', duration=duration) self.vnf['inputs'].update(dict(external_network_name=ext_net_name)) return True
def test_vnf(self): """Run IXIA Stress test on clearwater ims instance.""" start_time = time.time() cfy_client = self.orchestrator['object'] outputs = cfy_client.deployments.outputs.get( self.vnf['descriptor'].get('name'))['outputs'] dns_ip = outputs['dns_ip'] ellis_ip = outputs['ellis_ip'] self.__logger.info("Creating full IXIA network ...") subnet_settings = SubnetConfig(name='ixia_management_subnet', cidr='10.10.10.0/24', dns_nameservers=[env.get('NAMESERVER')]) network_settings = NetworkConfig(name='ixia_management_network', subnet_settings=[subnet_settings]) network_creator = OpenStackNetwork(self.snaps_creds, network_settings) network_creator.create() self.created_object.append(network_creator) ext_net_name = snaps_utils.get_ext_net_name(self.snaps_creds) router_creator = OpenStackRouter( self.snaps_creds, RouterConfig(name='ixia_management_router', external_gateway=ext_net_name, internal_subnets=[subnet_settings.name])) router_creator.create() self.created_object.append(router_creator) # security group creation self.__logger.info("Creating security groups for IXIA VMs") sg_rules = list() sg_rules.append( SecurityGroupRuleConfig(sec_grp_name="ixia_management", direction=Direction.ingress, protocol=Protocol.tcp, port_range_min=1, port_range_max=65535)) sg_rules.append( SecurityGroupRuleConfig(sec_grp_name="ixia_management", direction=Direction.ingress, protocol=Protocol.udp, port_range_min=1, port_range_max=65535)) sg_rules.append( SecurityGroupRuleConfig(sec_grp_name="ixia_management", direction=Direction.ingress, protocol=Protocol.icmp)) ixia_managment_sg_settings = SecurityGroupConfig( name="ixia_management", rule_settings=sg_rules) securit_group_creator = OpenStackSecurityGroup( self.snaps_creds, ixia_managment_sg_settings) securit_group_creator.create() self.created_object.append(securit_group_creator) sg_rules = list() sg_rules.append( SecurityGroupRuleConfig(sec_grp_name="ixia_ssh_http", direction=Direction.ingress, protocol=Protocol.tcp, port_range_min=1, port_range_max=65535)) ixia_ssh_http_sg_settings = SecurityGroupConfig(name="ixia_ssh_http", rule_settings=sg_rules) securit_group_creator = OpenStackSecurityGroup( self.snaps_creds, ixia_ssh_http_sg_settings) securit_group_creator.create() self.created_object.append(securit_group_creator) chassis_flavor_settings = FlavorConfig(name="ixia_vChassis", ram=4096, disk=40, vcpus=2) flavor_creator = OpenStackFlavor(self.snaps_creds, chassis_flavor_settings) flavor_creator.create() self.created_object.append(flavor_creator) card_flavor_settings = FlavorConfig(name="ixia_vCard", ram=4096, disk=4, vcpus=2) flavor_creator = OpenStackFlavor(self.snaps_creds, card_flavor_settings) flavor_creator.create() self.created_object.append(flavor_creator) load_flavor_settings = FlavorConfig(name="ixia_vLoad", ram=8192, disk=100, vcpus=4) flavor_creator = OpenStackFlavor(self.snaps_creds, load_flavor_settings) flavor_creator.create() self.created_object.append(flavor_creator) chassis_image_settings = ImageConfig( name=self.test['requirements']['chassis']['image'], image_user='******', exists=True) card_image_settings = ImageConfig( name=self.test['requirements']['card']['image'], image_user='******', exists=True) load_image_settings = ImageConfig( name=self.test['requirements']['load']['image'], image_user='******', exists=True) chassis_port_settings = PortConfig(name='ixia_chassis_port', network_name=network_settings.name) card1_port1_settings = PortConfig(name='ixia_card1_port1', network_name=network_settings.name) card2_port1_settings = PortConfig(name='ixia_card2_port1', network_name=network_settings.name) card1_port2_settings = PortConfig(name='ixia_card1_port2', network_name="cloudify_ims_network") card2_port2_settings = PortConfig(name='ixia_card2_port2', network_name="cloudify_ims_network") load_port_settings = PortConfig(name='ixia_load_port', network_name=network_settings.name) chassis_settings = VmInstanceConfig( name='ixia_vChassis', flavor=chassis_flavor_settings.name, port_settings=[chassis_port_settings], security_group_names=[ ixia_ssh_http_sg_settings.name, ixia_managment_sg_settings.name ], floating_ip_settings=[ FloatingIpConfig( name='ixia_vChassis_fip', port_name=chassis_port_settings.name, router_name=router_creator.router_settings.name) ]) vm_creator = OpenStackVmInstance(self.snaps_creds, chassis_settings, chassis_image_settings) self.__logger.info("Creating Ixia vChassis VM") vm_creator.create() fip_chassis = vm_creator.get_floating_ip().ip self.created_object.append(vm_creator) card1_settings = VmInstanceConfig( name='ixia_vCard1', flavor=card_flavor_settings.name, port_settings=[card1_port1_settings, card1_port2_settings], security_group_names=[ixia_managment_sg_settings.name]) vm_creator = OpenStackVmInstance(self.snaps_creds, card1_settings, card_image_settings) self.__logger.info("Creating Ixia vCard1 VM") vm_creator.create() vcard_ips = list() vcard_ips_p2 = list() vcard_ips.append(vm_creator.get_port_ip('ixia_card1_port1')) vcard_ips_p2.append(vm_creator.get_port_ip('ixia_card1_port2')) self.created_object.append(vm_creator) card2_settings = VmInstanceConfig( name='ixia_vCard2', flavor=card_flavor_settings.name, port_settings=[card2_port1_settings, card2_port2_settings], security_group_names=[ixia_managment_sg_settings.name]) vm_creator = OpenStackVmInstance(self.snaps_creds, card2_settings, card_image_settings) self.__logger.info("Creating Ixia vCard2 VM") vm_creator.create() vcard_ips.append(vm_creator.get_port_ip('ixia_card2_port1')) vcard_ips_p2.append(vm_creator.get_port_ip('ixia_card2_port2')) self.created_object.append(vm_creator) load_settings = VmInstanceConfig( name='ixia_vLoad', flavor=load_flavor_settings.name, port_settings=[load_port_settings], security_group_names=[ ixia_ssh_http_sg_settings.name, ixia_managment_sg_settings.name ], floating_ip_settings=[ FloatingIpConfig( name='ixia_vLoad_fip', port_name=load_port_settings.name, router_name=router_creator.router_settings.name) ]) vm_creator = OpenStackVmInstance(self.snaps_creds, load_settings, load_image_settings) self.__logger.info("Creating Ixia vLoad VM") vm_creator.create() fip_load = vm_creator.get_floating_ip().ip self.created_object.append(vm_creator) self.__logger.info("Chassis IP is: %s", fip_chassis) login_url = "https://" + str(fip_chassis) + "/api/v1/auth/session" cards_url = "https://" + str(fip_chassis) + "/api/v2/ixos/cards/" payload = json.dumps({ "username": "******", "password": "******", "rememberMe": "false" }) api_key = json.loads( (IxChassisUtils.ChassisRestAPI.postWithPayload(login_url, payload)))["apiKey"] self.__logger.info("Adding 2 card back inside the ixia chassis...") for ip in vcard_ips: payload = {"ipAddress": str(ip)} response = json.loads( IxChassisUtils.ChassisRestAPI.postOperation( cards_url, api_key, payload)) count = 0 while (int( IxChassisUtils.ChassisRestAPI.getWithHeaders( response['url'], api_key)['progress']) != 100): self.__logger.debug("Operation did not finish yet. \ Waiting for 1 more second..") time.sleep(1) if count > 60: raise Exception("Adding card take more than 60 seconds") count += 1 ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy()) ssh.connect(fip_chassis, username="******", password="******") cmd = "set license-check disable" run_blocking_ssh_command(ssh, cmd) cmd = "restart-service ixServer" run_blocking_ssh_command(ssh, cmd) self.config_ellis(ellis_ip) # Get IPs of P-CSCF resolver = dns.resolver.Resolver() resolver.nameservers = [dns_ip] result = resolver.query("bono.clearwater.local") iplistims = '' i = 0 for rdata in result: i = i + 1 print rdata.address iplistims += str(rdata.address) if i != len(result): iplistims += ';' kResourcesUrl = 'http://%s:%s/api/v0/resources' % (fip_load, 8080) kRxfPath = r"REG_CALL_OPNFV_v13.rxf" test_filname = self.test['inputs']['test_filname'] kGatewaySharedFolder = '/mnt/ixload-share/' kRxfRelativeUploadPath = 'uploads/%s' % os.path.split(kRxfPath)[1] kRxfAbsoluteUploadPath = os.path.join(kGatewaySharedFolder, kRxfRelativeUploadPath) kChassisList = [str(fip_chassis)] dataFileNameList = [ test_filname, 'Registration_only_LPS.tst', 'SIPCall.tst' ] kPortListPerCommunityCommunity = { "VoIP1@VM1": [(1, 1, 1)], "VoIP2@VM2": [(1, 2, 1)] } kStatsToDisplayDict = self.test['inputs']['stats'] connection = IxRestUtils.getConnection(fip_load, 8080) self.__logger.info("Creating a new session...") sessionUrl = IxLoadUtils.createSession(connection, self.test['version']) license_server = self.test['inputs']['licenseServer'] IxLoadUtils.configureLicenseServer(connection, sessionUrl, license_server) files_dir = os.path.join(self.case_dir, 'ixia/files') target_file = open(os.path.join(files_dir, test_filname), 'w') j2_env = Environment(loader=FileSystemLoader(files_dir), trim_blocks=True) self.test['inputs'].update( dict(ipchassis=fip_chassis, ipcard1=vcard_ips_p2[0], ipcard2=vcard_ips_p2[1], iplistims=iplistims)) target_file.write( j2_env.get_template(test_filname + '.template').render( self.test['inputs'])) target_file.close() self.__logger.info('Uploading files %s...' % kRxfPath) for dataFile in dataFileNameList: localFilePath = os.path.join(files_dir, dataFile) remoteFilePath = os.path.join(kGatewaySharedFolder, 'uploads/%s' % dataFile) IxLoadUtils.uploadFile(connection, kResourcesUrl, localFilePath, remoteFilePath) self.__logger.info('Upload file finished.') self.__logger.info("Loading repository %s..." % kRxfAbsoluteUploadPath) IxLoadUtils.loadRepository(connection, sessionUrl, kRxfAbsoluteUploadPath) self.__logger.info("Clearing chassis list...") IxLoadUtils.clearChassisList(connection, sessionUrl) self.__logger.info("Adding chassis %s..." % (kChassisList)) IxLoadUtils.addChassisList(connection, sessionUrl, kChassisList) self.__logger.info("Assigning new ports...") IxLoadUtils.assignPorts(connection, sessionUrl, kPortListPerCommunityCommunity) self.__logger.info("Starting the test...") IxLoadUtils.runTest(connection, sessionUrl) self.__logger.info("Polling values for stats %s..." % (kStatsToDisplayDict)) result = IxLoadUtils.pollStats(connection, sessionUrl, kStatsToDisplayDict) self.__logger.info("Test finished.") self.__logger.info("Checking test status...") testRunError = IxLoadUtils.getTestRunError(connection, sessionUrl) self.__logger.info(result) duration = time.time() - start_time self.details['test_vnf'].update(status='PASS', result=result, duration=duration) if testRunError: self.__logger.info("The test exited with following error: %s" % (testRunError)) self.details['test_vnf'].update(status='FAIL', duration=duration) return False else: self.__logger.info("The test completed successfully.") self.details['test_vnf'].update(status='PASS', duration=duration) self.result += 1 / 3 * 100 return True
def deploy_vnf(self): """Deploy ABOT-OAI-EPC.""" self.__logger.info("Upload VNFD") descriptor = self.vnf['descriptor'] self.__logger.info("Get or create flavor for all Abot-EPC") flavor_settings = FlavorConfig( name=self.vnf['requirements']['flavor']['name'], ram=self.vnf['requirements']['flavor']['ram_min'], disk=10, vcpus=1) flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings) flavor_creator.create() self.created_object.append(flavor_creator) self.__logger.info("Deploying Abot-epc bundle file ...") cmd = [ 'timeout', '-t', JujuEpc.juju_timeout, 'juju', 'deploy', '{}'.format(descriptor.get('file_name')) ] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) self.__logger.info("%s\n%s", " ".join(cmd), output) self.__logger.info("Waiting for instances .....") cmd = ['timeout', '-t', JujuEpc.juju_timeout, 'juju-wait'] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) self.__logger.info("%s\n%s", " ".join(cmd), output) self.__logger.info("Deployed Abot-epc on Openstack") nova_client = nova_utils.nova_client(self.snaps_creds) instances = get_instances(nova_client) self.__logger.info("List of Instance: %s", instances) for items in instances: metadata = get_instance_metadata(nova_client, items) if 'juju-units-deployed' in metadata: sec_group = 'juju-{}-{}'.format( metadata['juju-controller-uuid'], metadata['juju-model-uuid']) self.__logger.info("Instance: %s", sec_group) break self.__logger.info("Adding Security group rule....") # This will add sctp rule to a common Security Group Created # by juju and shared to all deployed units. self._add_custom_rule(sec_group) cmd = ['juju', 'status'] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) self.__logger.debug("%s\n%s", " ".join(cmd), output) for app in ['abot-epc-basic', 'oai-epc', 'oai-hss']: if not self.check_app(app): return False self.__logger.info("Copying the feature files to Abot_node ") cmd = [ 'timeout', '-t', JujuEpc.juju_timeout, 'juju', 'scp', '--', '-r', '-v', '{}/featureFiles'.format(self.case_dir), 'abot-epc-basic/0:~/' ] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) self.__logger.info("%s\n%s", " ".join(cmd), output) self.__logger.info("Copying the feature files in Abot_node ") cmd = [ 'timeout', '-t', JujuEpc.juju_timeout, 'juju', 'ssh', 'abot-epc-basic/0', 'sudo', 'rsync', '-azvv', '~/featureFiles', '/etc/rebaca-test-suite/featureFiles' ] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) self.__logger.info("%s\n%s", " ".join(cmd), output) return True
def deploy_vnf(self): start_time = time.time() self.__logger.info("Upload VNFD") cfy_client = self.orchestrator['object'] descriptor = self.vnf['descriptor'] self.deployment_name = descriptor.get('name') vrouter_blueprint_dir = os.path.join(self.data_dir, self.util.blueprint_dir) if not os.path.exists(vrouter_blueprint_dir): Repo.clone_from(descriptor.get('url'), vrouter_blueprint_dir, branch=descriptor.get('version')) cfy_client.blueprints.upload( vrouter_blueprint_dir + self.util.blueprint_file_name, descriptor.get('name')) self.__logger.info("Get or create flavor for vrouter") flavor_settings = FlavorSettings( name=self.vnf['requirements']['flavor']['name'], ram=self.vnf['requirements']['flavor']['ram_min'], disk=25, vcpus=1) flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings) flavor = flavor_creator.create() self.created_object.append(flavor_creator) # set image name glance = glance_utils.glance_client(self.snaps_creds) image = glance_utils.get_image(glance, "vyos1.1.7") self.vnf['inputs'].update(dict(target_vnf_image_id=image.id)) self.vnf['inputs'].update(dict(reference_vnf_image_id=image.id)) # set flavor id self.vnf['inputs'].update(dict(target_vnf_flavor_id=flavor.id)) self.vnf['inputs'].update(dict(reference_vnf_flavor_id=flavor.id)) self.vnf['inputs'].update(dict(keystone_username=self.tenant_name)) self.vnf['inputs'].update(dict(keystone_password=self.tenant_name)) self.vnf['inputs'].update(dict(keystone_tenant_name=self.tenant_name)) self.vnf['inputs'].update( dict(keystone_url=os_utils.get_endpoint('identity'))) self.__logger.info("Create VNF Instance") cfy_client.deployments.create(descriptor.get('name'), descriptor.get('name'), self.vnf.get('inputs')) wait_for_execution(cfy_client, get_execution_id(cfy_client, descriptor.get('name')), self.__logger, timeout=7200) self.__logger.info("Start the VNF Instance deployment") execution = cfy_client.executions.start(descriptor.get('name'), 'install') # Show execution log execution = wait_for_execution(cfy_client, execution, self.__logger) duration = time.time() - start_time self.__logger.info(execution) if execution.status == 'terminated': self.details['vnf'].update(status='PASS', duration=duration) result = True else: self.details['vnf'].update(status='FAIL', duration=duration) result = False return result
def _prepare_env(self): """Create resources needed by test scenarios.""" LOGGER.debug('Validating the test name...') if self.test_name not in self.TESTS: raise Exception("Test name '%s' is invalid" % self.test_name) network_name = self.RALLY_PRIVATE_NET_NAME + self.guid subnet_name = self.RALLY_PRIVATE_SUBNET_NAME + self.guid router_name = self.RALLY_ROUTER_NAME + self.guid self.image_name = self.GLANCE_IMAGE_NAME + self.guid self.flavor_name = self.FLAVOR_NAME + self.guid self.flavor_alt_name = self.FLAVOR_ALT_NAME + self.guid self.ext_net_name = snaps_utils.get_ext_net_name(self.os_creds) self.compute_cnt = snaps_utils.get_active_compute_cnt(self.os_creds) LOGGER.debug("Creating image '%s'...", self.image_name) image_creator = deploy_utils.create_image( self.os_creds, ImageConfig( name=self.image_name, image_file=self.GLANCE_IMAGE_PATH, img_format=self.GLANCE_IMAGE_FORMAT, image_user=self.GLANCE_IMAGE_USERNAME, public=True, extra_properties=self.GLANCE_IMAGE_EXTRA_PROPERTIES)) if image_creator is None: raise Exception("Failed to create image") self.creators.append(image_creator) LOGGER.debug("Creating network '%s'...", network_name) rally_network_type = None rally_physical_network = None rally_segmentation_id = None if hasattr(CONST, 'rally_network_type'): rally_network_type = CONST.__getattribute__( 'rally_network_type') if hasattr(CONST, 'rally_physical_network'): rally_physical_network = CONST.__getattribute__( 'rally_physical_network') if hasattr(CONST, 'rally_segmentation_id'): rally_segmentation_id = CONST.__getattribute__( 'rally_segmentation_id') network_creator = deploy_utils.create_network( self.os_creds, NetworkConfig( name=network_name, shared=True, network_type=rally_network_type, physical_network=rally_physical_network, segmentation_id=rally_segmentation_id, subnet_settings=[SubnetConfig( name=subnet_name, cidr=self.RALLY_PRIVATE_SUBNET_CIDR)])) if network_creator is None: raise Exception("Failed to create private network") self.priv_net_id = network_creator.get_network().id self.creators.append(network_creator) LOGGER.debug("Creating router '%s'...", router_name) router_creator = deploy_utils.create_router( self.os_creds, RouterConfig( name=router_name, external_gateway=self.ext_net_name, internal_subnets=[subnet_name])) if router_creator is None: raise Exception("Failed to create router") self.creators.append(router_creator) LOGGER.debug("Creating flavor '%s'...", self.flavor_name) flavor_creator = OpenStackFlavor( self.os_creds, FlavorConfig( name=self.flavor_name, ram=self.FLAVOR_RAM, disk=1, vcpus=1, metadata=self.FLAVOR_EXTRA_SPECS)) if flavor_creator is None or flavor_creator.create() is None: raise Exception("Failed to create flavor") self.creators.append(flavor_creator) LOGGER.debug("Creating flavor '%s'...", self.flavor_alt_name) flavor_alt_creator = OpenStackFlavor( self.os_creds, FlavorConfig( name=self.flavor_alt_name, ram=self.FLAVOR_RAM_ALT, disk=1, vcpus=1, metadata=self.FLAVOR_EXTRA_SPECS)) if flavor_alt_creator is None or flavor_alt_creator.create() is None: raise Exception("Failed to create flavor") self.creators.append(flavor_alt_creator)
def deploy_orchestrator(self): # pylint: disable=too-many-locals """ Create network, subnet, router Bootstrap juju """ self.__logger.info("Deployed Orchestrator") private_net_name = CONST.__getattribute__( 'vnf_{}_private_net_name'.format(self.case_name)) private_subnet_name = CONST.__getattribute__( 'vnf_{}_private_subnet_name'.format(self.case_name)) private_subnet_cidr = CONST.__getattribute__( 'vnf_{}_private_subnet_cidr'.format(self.case_name)) abot_router = CONST.__getattribute__( 'vnf_{}_external_router'.format(self.case_name)) dns_nameserver = CONST.__getattribute__( 'vnf_{}_dns_nameserver'.format(self.case_name)) ext_net_name = CONST.__getattribute__( 'vnf_{}_external_network_name'.format(self.case_name)) self.__logger.info("Creating full network ...") subnet_settings = SubnetSettings(name=private_subnet_name, cidr=private_subnet_cidr, dns_nameservers=dns_nameserver) network_settings = NetworkSettings(name=private_net_name, subnet_settings=[subnet_settings]) network_creator = OpenStackNetwork(self.snaps_creds, network_settings) network_creator.create() self.created_object.append(network_creator) ext_net_name = snaps_utils.get_ext_net_name(self.snaps_creds) self.__logger.info("Creating network Router ....") router_creator = OpenStackRouter( self.snaps_creds, RouterSettings( name=abot_router, external_gateway=ext_net_name, internal_subnets=[subnet_settings.name])) router_creator.create() self.created_object.append(router_creator) self.__logger.info("Creating Flavor ....") flavor_settings = FlavorSettings( name=self.orchestrator['requirements']['flavor']['name'], ram=self.orchestrator['requirements']['flavor']['ram_min'], disk=10, vcpus=1) flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings) self.__logger.info("Juju Bootstrap: Skip creation of flavors") flavor_creator.create() self.created_object.append(flavor_creator) self.__logger.info("Installing Dependency Packages .......") source_dir = "/src/epc-requirements/juju_bin_build" if os.path.exists(source_dir): shutil.rmtree(source_dir) os.makedirs(source_dir) os.environ['GOPATH'] = str(source_dir) os.environ['GOBIN'] = str(source_dir) + "/bin" os.environ['PATH'] = ((os.path.expandvars('$GOPATH')) + ":" + (os.path.expandvars('$GOBIN')) + ":" + (os.path.expandvars('$PATH'))) os.system('go get -d -v github.com/juju/juju/...') os.chdir(source_dir + "/src" + "/github.com" + "/juju" + "/juju") os.system('git checkout tags/juju-2.2.5') os.system('go get github.com/rogpeppe/godeps') os.system('godeps -u dependencies.tsv') os.system('go install -v github.com/juju/juju/...') self.__logger.info("Creating Cloud for Abot-epc .....") os.system('juju add-cloud abot-epc -f {}'.format(self.filename)) os.system('juju add-credential abot-epc -f {}'.format(self.filename)) for image_name in self.images.keys(): self.__logger.info("Generating Metadata for %s", image_name) image_id = os_utils.get_image_id(self.glance_client, image_name) os.system( 'juju metadata generate-image -d ~ -i {} -s {} -r ' '{} -u {}'.format( image_id, image_name, os.environ.get("OS_REGION_NAME", self.default_region_name), self.public_auth_url)) net_id = os_utils.get_network_id(self.neutron_client, private_net_name) self.__logger.info("Credential information : %s", net_id) juju_bootstrap_command = ('juju bootstrap abot-epc abot-controller ' '--config network={} --metadata-source ~ ' '--config ssl-hostname-verification=false ' '--constraints mem=2G --bootstrap-series ' 'xenial ' '--config use-floating-ip=true --debug'. format(net_id)) os.system(juju_bootstrap_command) return True
class MagnumUtilsClusterTypeTests(OSComponentTestCase): """ Tests individual functions within magnum_utils.py """ def setUp(self): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.cluster_type_name = self.guid + '-cluster-type' self.magnum = magnum_utils.magnum_client( self.os_creds, self.os_session) metadata = self.image_metadata if not metadata: metadata = dict() if 'extra_properties' not in metadata: metadata['extra_properties'] = dict() metadata['extra_properties']['os_distro'] = 'cirros' os_image_settings = openstack_tests.cirros_image_settings( name=self.guid + '-image', image_metadata=metadata) self.image_creator = OpenStackImage(self.os_creds, os_image_settings) self.flavor_creator = OpenStackFlavor( self.os_creds, FlavorConfig( name=self.guid + '-flavor', ram=512, disk=10, vcpus=1)) keypair_priv_filepath = 'tmp/' + self.guid keypair_pub_filepath = keypair_priv_filepath + '.pub' self.keypair_creator = OpenStackKeypair( self.os_creds, KeypairConfig( name=self.guid + '-keypair', public_filepath=keypair_pub_filepath, private_filepath=keypair_priv_filepath)) self.cluster_template = None try: self.image_creator.create() self.flavor_creator.create() self.keypair_creator.create() except: self.tearDown() raise def tearDown(self): if self.cluster_template: try: magnum_utils.delete_cluster_template( self.magnum, self.cluster_template.id) except: pass if self.keypair_creator: try: self.keypair_creator.clean() except: pass if self.flavor_creator: try: self.flavor_creator.clean() except: pass if self.image_creator: try: self.image_creator.clean() except: pass super(self.__class__, self).__clean__() def test_create_cluster_template_simple(self): config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name) self.cluster_template = magnum_utils.create_cluster_template( self.magnum, config) self.assertIsNotNone(self.cluster_template) self.assertTrue( validate_cluster_template(config, self.cluster_template)) template_by_name = magnum_utils.get_cluster_template( self.magnum, template_name=config.name) self.assertEqual(self.cluster_template, template_by_name) template_by_id = magnum_utils.get_cluster_template_by_id( self.magnum, self.cluster_template.id) self.assertEqual(self.cluster_template, template_by_id) def test_create_cluster_template_all(self): config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, network_driver='flannel', external_net=self.ext_net_name, floating_ip_enabled=True, docker_volume_size=100, server_type=ServerType.vm, flavor=self.flavor_creator.flavor_settings.name, master_flavor=self.flavor_creator.flavor_settings.name, coe=ContainerOrchestrationEngine.kubernetes, fixed_net='foo', fixed_subnet='bar', registry_enabled=True, insecure_registry='localhost', docker_storage_driver=DockerStorageDriver.overlay, dns_nameserver='8.8.4.4', public=True, tls_disabled=True, http_proxy=None, https_proxy=None, volume_driver='cinder', master_lb_enabled=False, labels={'foo': 'bar'}) self.cluster_template = magnum_utils.create_cluster_template( self.magnum, config) self.assertIsNotNone(self.cluster_template) self.assertTrue( validate_cluster_template(config, self.cluster_template)) template_by_name = magnum_utils.get_cluster_template( self.magnum, template_name=config.name) self.assertEqual(self.cluster_template, template_by_name) template_by_id = magnum_utils.get_cluster_template_by_id( self.magnum, self.cluster_template.id) self.assertEqual(self.cluster_template, template_by_id) def test_create_cluster_template_bad_image(self): config = ClusterTemplateConfig( name=self.cluster_type_name, image='foo', keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name) with self.assertRaises(BadRequest): self.cluster_template = magnum_utils.create_cluster_template( self.magnum, config) def test_create_cluster_template_bad_ext_net(self): config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net='foo', flavor=self.flavor_creator.flavor_settings.name) with self.assertRaises(BadRequest): self.cluster_template = magnum_utils.create_cluster_template( self.magnum, config) def test_create_cluster_template_bad_flavor(self): config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor='foo') with self.assertRaises(BadRequest): self.cluster_template = magnum_utils.create_cluster_template( self.magnum, config) def test_create_cluster_template_bad_master_flavor(self): config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, flavor=self.flavor_creator.flavor_settings.name, master_flavor='foo') with self.assertRaises(BadRequest): self.cluster_template = magnum_utils.create_cluster_template( self.magnum, config) def test_create_cluster_template_bad_network_driver(self): config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, network_driver='foo') with self.assertRaises(BadRequest): self.cluster_template = magnum_utils.create_cluster_template( self.magnum, config) def test_create_cluster_template_bad_volume_driver(self): config = ClusterTemplateConfig( name=self.cluster_type_name, image=self.image_creator.image_settings.name, keypair=self.keypair_creator.keypair_settings.name, external_net=self.ext_net_name, volume_driver='foo') with self.assertRaises(BadRequest): self.cluster_template = magnum_utils.create_cluster_template( self.magnum, config)