def test_config_with_name_user_format_only(self): with self.assertRaises(ImageConfigError): ImageConfig(**{ 'name': 'foo', 'image_user': '******', 'format': 'qcow2' })
def test_create_same_image_new_settings(self): """ Tests the creation of an OpenStack image when the image already exists and the configuration only contains the name. """ # Create Image self.image_creator = create_image.OpenStackImage(self.os_creds, self.image_settings) image1 = self.image_creator.create() retrieved_image = glance_utils.get_image( self.glance, image_settings=self.image_settings) self.assertIsNotNone(retrieved_image) self.assertEqual(self.image_creator.get_image().size, retrieved_image.size) self.assertEqual(get_image_size(self.image_settings), retrieved_image.size) self.assertEqual(image1.name, retrieved_image.name) self.assertEqual(image1.id, retrieved_image.id) self.assertEqual(image1.properties, retrieved_image.properties) # Should be retrieving the instance data image_2_settings = ImageConfig(name=self.image_settings.name, image_user='******', exists=True) os_image_2 = create_image.OpenStackImage(self.os_creds, image_2_settings) image2 = os_image_2.create() self.assertEqual(image1.id, image2.id)
def prepare(self): """Prepare testscase (Additional pre-configuration steps).""" super(CloudifyIms, self).prepare() self.__logger.info("Additional pre-configuration steps") compute_quotas = self.os_project.get_compute_quotas() network_quotas = self.os_project.get_network_quotas() for key, value in (self.vnf['requirements']['compute_quotas'].items()): setattr(compute_quotas, key, value) for key, value in (self.vnf['requirements']['network_quotas'].items()): setattr(network_quotas, key, value) compute_quotas = self.os_project.update_compute_quotas(compute_quotas) network_quotas = self.os_project.update_network_quotas(network_quotas) # needs some images self.__logger.info("Upload some OS images if it doesn't exist") for image_name, image_file in self.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_creator.create()
def test_name_user_format_url_only(self): settings = ImageConfig(name='foo', image_user='******', img_format='qcow2', url='http://foo.com') self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.image_user) self.assertEqual('qcow2', settings.format) self.assertEqual('http://foo.com', settings.url) self.assertIsNone(settings.image_file) self.assertFalse(settings.exists) self.assertFalse(settings.public) self.assertIsNone(settings.nic_config_pb_loc)
def test_all_url(self): properties = {'hw_video_model': 'vga'} kernel_settings = ImageConfig(name='kernel', url='http://kernel.com', image_user='******', img_format='qcow2') ramdisk_settings = ImageConfig(name='ramdisk', url='http://ramdisk.com', image_user='******', img_format='qcow2') settings = ImageConfig(name='foo', image_user='******', img_format='qcow2', url='http://foo.com', extra_properties=properties, nic_config_pb_loc='/foo/bar', kernel_image_settings=kernel_settings, ramdisk_image_settings=ramdisk_settings, exists=True, public=True) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.image_user) self.assertEqual('qcow2', settings.format) self.assertEqual('http://foo.com', settings.url) self.assertEqual(properties, settings.extra_properties) self.assertIsNone(settings.image_file) self.assertEqual('/foo/bar', settings.nic_config_pb_loc) self.assertEqual('kernel', settings.kernel_image_settings.name) self.assertEqual('http://kernel.com', settings.kernel_image_settings.url) self.assertEqual('bar', settings.kernel_image_settings.image_user) self.assertEqual('qcow2', settings.kernel_image_settings.format) self.assertEqual('ramdisk', settings.ramdisk_image_settings.name) self.assertEqual('http://ramdisk.com', settings.ramdisk_image_settings.url) self.assertEqual('bar', settings.ramdisk_image_settings.image_user) self.assertEqual('qcow2', settings.ramdisk_image_settings.format) self.assertTrue(settings.exists) self.assertTrue(settings.public)
def prepare_images(self): """Upload images if they doen't exist yet""" self.logger.info("Upload images if they doen't exist yet") for image_name, image_file in self.images.iteritems(): self.logger.info("image: %s, file: %s", image_name, image_file) if image_file and image_name: image = OpenStackImage( self.snaps_creds, ImageConfig(name=image_name, image_user='******', img_format='qcow2', image_file=image_file, public=True)) image.create()
def test_bad_image_file(self): """ Expect an ImageCreationError when the image file does not exist """ os_image_settings = openstack_tests.cirros_image_settings( name=self.image_name) self.image_creator = create_image.OpenStackImage( self.os_creds, ImageConfig( name=os_image_settings.name, image_user=os_image_settings.image_user, img_format=os_image_settings.format, image_file="/foo/bar.qcow")) with self.assertRaises(IOError): self.image_creator.create()
def test_bad_image_image_type(self): """ Expect an ImageCreationError when the image type bad """ os_image_settings = openstack_tests.cirros_image_settings( name=self.image_name) self.image_creator = create_image.OpenStackImage( self.os_creds, ImageConfig( name=os_image_settings.name, image_user=os_image_settings.image_user, img_format='foo', url=os_image_settings.url)) with self.assertRaises(Exception): self.image_creator.create()
def test_bad_image_name(self): """ Expect an ImageCreationError when the image name does not exist when a file or URL has not been configured """ os_image_settings = ImageConfig(name='foo', image_user='******', exists=True) self.image_creator = create_image.OpenStackImage(self.os_creds, os_image_settings) with self.assertRaises(ImageCreationError): self.image_creator.create() self.fail('ImageCreationError should have been raised prior to' 'this line')
def register_glance_image(self, name, url, img_format, public): logger.info("Registering the image...") # Check whether the image is local or not if 'http' in url: image_settings = ImageConfig(name=name, img_format=img_format, url=url, public=public, image_user='******') else: image_settings = ImageConfig(name=name, img_format=img_format, image_file=url, public=public, image_user='******') # TODO Remove this when tacker is part of SNAPS self.image_settings = image_settings image_creator = OpenStackImage(self.os_creds, image_settings) image_creator.create() self.creators.append(image_creator) return image_creator
def prepare(self): super(CloudifyVrouter, self).prepare() self.__logger.info("Additional pre-configuration steps") self.util.set_credentials(self.snaps_creds) self.__logger.info("Upload some OS images if it doesn't exist") for image_name, image_file in self.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_creator.create() self.created_object.append(image_creator)
def test_config_with_name_user_format_file_only(self): settings = ImageConfig( **{ 'name': 'foo', 'image_user': '******', 'format': 'qcow2', 'image_file': '/foo/bar.qcow' }) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.image_user) self.assertEqual('qcow2', settings.format) self.assertIsNone(settings.url) self.assertEqual('/foo/bar.qcow', settings.image_file) self.assertFalse(settings.exists) self.assertFalse(settings.public) self.assertIsNone(settings.nic_config_pb_loc)
def test_config_with_name_user_format_url_only(self): settings = ImageConfig( **{ 'name': 'foo', 'image_user': '******', 'format': 'qcow2', 'download_url': 'http://foo.com' }) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.image_user) self.assertEqual('qcow2', settings.format) self.assertEqual('http://foo.com', settings.url) self.assertIsNone(settings.image_file) self.assertFalse(settings.exists) self.assertFalse(settings.public) self.assertIsNone(settings.nic_config_pb_loc)
def test_name_user_format_url_only_properties(self): properties = {'hw_video_model': 'vga'} settings = ImageConfig(name='foo', image_user='******', img_format='qcow2', url='http://foo.com', extra_properties=properties) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.image_user) self.assertEqual('qcow2', settings.format) self.assertEqual('http://foo.com', settings.url) self.assertEqual(properties, settings.extra_properties) self.assertIsNone(settings.image_file) self.assertFalse(settings.exists) self.assertFalse(settings.public) self.assertIsNone(settings.nic_config_pb_loc)
def test_all_file(self): properties = {'hw_video_model': 'vga'} settings = ImageConfig(name='foo', image_user='******', img_format='qcow2', image_file='/foo/bar.qcow', extra_properties=properties, nic_config_pb_loc='/foo/bar', exists=True, public=True) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.image_user) self.assertEqual('qcow2', settings.format) self.assertIsNone(settings.url) self.assertEqual('/foo/bar.qcow', settings.image_file) self.assertEqual(properties, settings.extra_properties) self.assertEqual('/foo/bar', settings.nic_config_pb_loc) self.assertTrue(settings.exists) self.assertTrue(settings.public)
def test_config_all_url(self): settings = ImageConfig( **{ 'name': 'foo', 'image_user': '******', 'format': 'qcow2', 'download_url': 'http://foo.com', 'extra_properties': '{\'hw_video_model\': \'vga\'}', 'nic_config_pb_loc': '/foo/bar', 'kernel_image_settings': { 'name': 'kernel', 'download_url': 'http://kernel.com', 'image_user': '******', 'format': 'qcow2' }, 'ramdisk_image_settings': { 'name': 'ramdisk', 'download_url': 'http://ramdisk.com', 'image_user': '******', 'format': 'qcow2' }, 'exists': True, 'public': True }) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.image_user) self.assertEqual('qcow2', settings.format) self.assertEqual('http://foo.com', settings.url) self.assertEqual('{\'hw_video_model\': \'vga\'}', settings.extra_properties) self.assertIsNone(settings.image_file) self.assertEqual('/foo/bar', settings.nic_config_pb_loc) self.assertEqual('kernel', settings.kernel_image_settings.name) self.assertEqual('http://kernel.com', settings.kernel_image_settings.url) self.assertEqual('ramdisk', settings.ramdisk_image_settings.name) self.assertEqual('http://ramdisk.com', settings.ramdisk_image_settings.url) self.assertTrue(settings.exists) self.assertTrue(settings.public)
def test_config_all_file(self): settings = ImageConfig( **{ 'name': 'foo', 'image_user': '******', 'format': 'qcow2', 'image_file': '/foo/bar.qcow', 'extra_properties': '{\'hw_video_model\' : \'vga\'}', 'nic_config_pb_loc': '/foo/bar', 'exists': True, 'public': True }) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.image_user) self.assertEqual('qcow2', settings.format) self.assertIsNone(settings.url) self.assertEqual('/foo/bar.qcow', settings.image_file) self.assertEqual('{\'hw_video_model\' : \'vga\'}', settings.extra_properties) self.assertEqual('/foo/bar', settings.nic_config_pb_loc) self.assertTrue(settings.exists) self.assertTrue(settings.public)
def test_bad_image_url(self): """ Expect an ImageCreationError when the image download url is bad """ os_image_settings = openstack_tests.cirros_image_settings( name=self.image_name) self.image_creator = create_image.OpenStackImage( self.os_creds, ImageConfig( name=os_image_settings.name, image_user=os_image_settings.image_user, img_format=os_image_settings.format, url="http://foo.bar")) try: self.image_creator.create() except HTTPBadRequest: pass except URLError: pass except Exception as e: self.fail('Invalid Exception ' + str(e))
def test_empty_config(self): with self.assertRaises(ImageConfigError): ImageConfig(**dict())
def test_name_user_format_only(self): with self.assertRaises(ImageConfigError): ImageConfig(name='foo', image_user='******', img_format='qcow2')
def deploy_orchestrator(self): # pylint: disable=too-many-locals """ Create network, subnet, router Bootstrap juju """ self.__logger.info("Deployed Orchestrator") private_net_name = getattr( config.CONF, 'vnf_{}_private_net_name'.format(self.case_name)) private_subnet_name = '{}-{}'.format( getattr(config.CONF, 'vnf_{}_private_subnet_name'.format(self.case_name)), self.uuid) private_subnet_cidr = getattr( config.CONF, 'vnf_{}_private_subnet_cidr'.format(self.case_name)) abot_router = '{}-{}'.format( getattr(config.CONF, 'vnf_{}_external_router'.format(self.case_name)), self.uuid) self.__logger.info("Creating full network ...") subnet_settings = SubnetConfig(name=private_subnet_name, cidr=private_subnet_cidr, dns_nameservers=[env.get('NAMESERVER')]) 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 cmd = [ 'timeout', '-t', JujuEpc.juju_timeout, 'juju', 'metadata', 'generate-image', '-d', '/root', '-i', image_id, '-s', image_name, '-r', self.snaps_creds.region_name, '-u', self.public_auth_url ] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) self.__logger.info("%s\n%s", " ".join(cmd), output) self.created_object.append(image_creator) self.__logger.info("Network ID : %s", net_id) cmd = [ 'timeout', '-t', JujuEpc.juju_timeout, 'juju', 'bootstrap', 'abot-epc', 'abot-controller', '--metadata-source', '/root', '--constraints', 'mem=2G', '--bootstrap-series', 'xenial', '--config', 'network={}'.format(net_id), '--config', 'ssl-hostname-verification=false', '--config', 'use-floating-ip=true', '--config', 'use-default-secgroup=true', '--debug' ] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) self.__logger.info("%s\n%s", " ".join(cmd), output) return True
def test_config_with_name_only(self): with self.assertRaises(ImageConfigError): ImageConfig(**{'name': 'foo'})
def test_name_user_only(self): with self.assertRaises(ImageConfigError): ImageConfig(name='foo', image_user='******')
def test_name_only(self): with self.assertRaises(ImageConfigError): ImageConfig(name='foo')
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
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 test_no_params(self): with self.assertRaises(ImageConfigError): ImageConfig()
def deploy_orchestrator(self): self.logger.info("Deploying Open Baton...") self.logger.info("Details: %s", self.mano['details']) start_time = time.time() self.logger.info("Creating orchestra instance...") userdata = get_userdata(self.mano) self.logger.info("flavor: %s\n" "image: %s\n" "network_id: %s\n", self.mano['details']['flavor']['name'], self.mano['requirements']['image'], self.mano['details']['network']['id']) self.logger.debug("userdata: %s\n", userdata) # setting up image image_settings = ImageConfig(name=self.mano['requirements']['image'], image_user='******', exists=True) # setting up port port_settings = PortConfig( name='%s_port' % self.case_name, network_name=self.mano['details']['network']['name']) # build configuration of vm orchestra_settings = VmInstanceConfig( name=self.case_name, flavor=self.mano['details']['flavor']['name'], port_settings=[port_settings], security_group_names=[self.mano['details']['sec_group']], userdata=str(userdata)) orchestra_vm = OpenStackVmInstance(self.snaps_creds, orchestra_settings, image_settings) orchestra_vm.create() self.created_resources.append(orchestra_vm) self.mano['details']['id'] = orchestra_vm.get_vm_info()['id'] self.logger.info("Created orchestra instance: %s", self.mano['details']['id']) self.logger.info("Associating floating ip: '%s' to VM '%s' ", self.mano['details']['fip'].ip, self.case_name) nova_client = os_utils.get_nova_client() if not os_utils.add_floating_ip(nova_client, self.mano['details']['id'], self.mano['details']['fip'].ip): duration = time.time() - start_time self.details["orchestrator"].update(status='FAIL', duration=duration) self.logger.error("Cannot associate floating IP to VM.") return False self.logger.info("Waiting for Open Baton NFVO to be up and running...") timeout = 0 while timeout < 20: if servertest(self.mano['details']['fip'].ip, "8080"): break else: self.logger.info("Open Baton NFVO is not started yet (%ss)", (timeout * 60)) time.sleep(60) timeout += 1 if timeout >= 20: duration = time.time() - start_time self.details["orchestrator"].update(status='FAIL', duration=duration) self.logger.error("Open Baton is not started correctly") return False self.logger.info("Waiting for all components to be up and running...") time.sleep(60) duration = time.time() - start_time self.details["orchestrator"].update(status='PASS', duration=duration) self.logger.info("Deploy Open Baton NFVO: OK") 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_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_ims.pem") keypair_settings = KeypairConfig(name='cloudify_ims_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 = SubnetConfig(name='cloudify_ims_subnet', cidr='10.67.79.0/24') network_settings = NetworkConfig(name='cloudify_ims_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='cloudify_ims_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( SecurityGroupRuleConfig(sec_grp_name="sg-cloudify-manager", direction=Direction.ingress, protocol=Protocol.tcp, port_range_min=1, port_range_max=65535)) sg_rules.append( SecurityGroupRuleConfig(sec_grp_name="sg-cloudify-manager", direction=Direction.ingress, protocol=Protocol.udp, port_range_min=1, port_range_max=65535)) securit_group_creator = OpenStackSecurityGroup( self.snaps_creds, SecurityGroupConfig(name="sg-cloudify-manager", rule_settings=sg_rules)) securit_group_creator.create() self.created_object.append(securit_group_creator) # orchestrator VM flavor self.__logger.info("Get or create flavor for cloudify manager vm ...") flavor_settings = FlavorConfig( 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 = ImageConfig( name=self.orchestrator['requirements']['os_image'], image_user='******', exists=True) port_settings = PortConfig(name='cloudify_manager_port', network_name=network_settings.name) manager_settings = VmInstanceConfig( name='cloudify_manager', flavor=flavor_settings.name, port_settings=[port_settings], security_group_names=[securit_group_creator.sec_grp_settings.name], floating_ip_settings=[ FloatingIpConfig( 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 = keystone_utils.get_endpoint(self.snaps_creds, 'identity') self.__logger.info("Set creds for cloudify manager") cfy_creds = dict(keystone_username=self.snaps_creds.username, keystone_password=self.snaps_creds.password, keystone_tenant_name=self.snaps_creds.project_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.__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_ims.pem /etc/cloudify/" run_blocking_ssh_command(ssh, cmd) cmd = "sudo chmod 444 /etc/cloudify/cloudify_ims.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, network_name=network_settings.name)) self.result = 1 / 3 * 100 return True