def test_all_type_enums(self): host_routes = {'destination': '0.0.0.0/0', 'nexthop': '123.456.78.9'} settings = SubnetSettings( name='foo', cidr='10.0.0.0/24', ip_version=6, project_name='bar-project', start='10.0.0.2', end='10.0.0.101', gateway_ip='10.0.0.1', enable_dhcp=False, dns_nameservers=['8.8.8.8'], host_routes=[host_routes], destination='dest', nexthop='hop', ipv6_ra_mode=IPv6Mode_old.stateful, ipv6_address_mode=IPv6Mode.slaac) self.assertEqual('foo', settings.name) self.assertEqual('10.0.0.0/24', settings.cidr) self.assertEqual(6, settings.ip_version) self.assertEqual('bar-project', settings.project_name) self.assertEqual('10.0.0.2', settings.start) self.assertEqual('10.0.0.101', settings.end) self.assertEqual('10.0.0.1', settings.gateway_ip) self.assertEqual(False, settings.enable_dhcp) self.assertEqual(1, len(settings.dns_nameservers)) self.assertEqual('8.8.8.8', settings.dns_nameservers[0]) self.assertEqual(1, len(settings.host_routes)) self.assertEqual(host_routes, settings.host_routes[0]) self.assertEqual('dest', settings.destination) self.assertEqual('hop', settings.nexthop) self.assertEqual(IPv6Mode.stateful.value, settings.ipv6_ra_mode.value) self.assertEqual(IPv6Mode.slaac.value, settings.ipv6_address_mode.value)
def prepare_network(self): """Create network/subnet/router if they doen't exist yet""" self.logger.info( "Creating network/subnet/router if they doen't exist yet...") subnet_settings = SubnetSettings(name='%s_subnet' % self.case_name, cidr="192.168.100.0/24") network_settings = NetworkSettings(name='%s_net' % self.case_name, subnet_settings=[subnet_settings]) orchestra_network = OpenStackNetwork(self.snaps_creds, network_settings) orchestra_network_info = orchestra_network.create() self.mano['details']['network'] = {} self.mano['details']['network']['id'] = orchestra_network_info.id self.mano['details']['network']['name'] = orchestra_network_info.name self.mano['details']['external_net_name'] = snaps_utils.\ get_ext_net_name(self.snaps_creds) self.created_resources.append(orchestra_network) orchestra_router = OpenStackRouter( self.snaps_creds, RouterSettings( name='%s_router' % self.case_name, external_gateway=self.mano['details']['external_net_name'], internal_subnets=[subnet_settings.name])) orchestra_router.create() self.created_resources.append(orchestra_router) self.logger.info("Created network and router for Open Baton NFVO...")
def test_config_all(self): host_routes = {'destination': '0.0.0.0/0', 'nexthop': '123.456.78.9'} settings = SubnetSettings( **{'name': 'foo', 'cidr': '10.0.0.0/24', 'ip_version': 6, 'project_name': 'bar-project', 'start': '10.0.0.2', 'end': '10.0.0.101', 'gateway_ip': '10.0.0.1', 'enable_dhcp': False, 'dns_nameservers': ['8.8.8.8'], 'host_routes': [host_routes], 'destination': 'dest', 'nexthop': 'hop', 'ipv6_ra_mode': 'dhcpv6-stateless', 'ipv6_address_mode': 'slaac'}) self.assertEqual('foo', settings.name) self.assertEqual('10.0.0.0/24', settings.cidr) self.assertEqual(6, settings.ip_version) self.assertEqual('bar-project', settings.project_name) self.assertEqual('10.0.0.2', settings.start) self.assertEqual('10.0.0.101', settings.end) self.assertEqual('10.0.0.1', settings.gateway_ip) self.assertEqual(False, settings.enable_dhcp) self.assertEqual(1, len(settings.dns_nameservers)) self.assertEqual('8.8.8.8', settings.dns_nameservers[0]) self.assertEqual(1, len(settings.host_routes)) self.assertEqual(host_routes, settings.host_routes[0]) self.assertEqual('dest', settings.destination) self.assertEqual('hop', settings.nexthop) self.assertEqual(IPv6Mode.stateless.value, settings.ipv6_ra_mode.value) self.assertEqual(IPv6Mode.slaac.value, settings.ipv6_address_mode.value)
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 test_name_cidr_only(self): settings = SubnetSettings(name='foo', cidr='10.0.0.0/24') self.assertEqual('foo', settings.name) self.assertEqual('10.0.0.0/24', settings.cidr) self.assertEqual(4, settings.ip_version) self.assertIsNone(settings.project_name) self.assertIsNone(settings.start) self.assertIsNone(settings.end) self.assertIsNone(settings.enable_dhcp) self.assertEqual(0, len(settings.dns_nameservers)) self.assertIsNone(settings.host_routes) self.assertIsNone(settings.destination) self.assertIsNone(settings.nexthop) self.assertIsNone(settings.ipv6_ra_mode) self.assertIsNone(settings.ipv6_address_mode)
def test_config_with_name_cidr_only(self): settings = SubnetSettings(**{'name': 'foo', 'cidr': '10.0.0.0/24'}) self.assertEqual('foo', settings.name) self.assertEqual('10.0.0.0/24', settings.cidr) self.assertEqual(4, settings.ip_version) self.assertIsNone(settings.project_name) self.assertIsNone(settings.start) self.assertIsNone(settings.end) self.assertIsNone(settings.gateway_ip) self.assertIsNone(settings.enable_dhcp) self.assertEqual(0, len(settings.dns_nameservers)) self.assertIsNone(settings.host_routes) self.assertIsNone(settings.destination) self.assertIsNone(settings.nexthop) self.assertIsNone(settings.ipv6_ra_mode) self.assertIsNone(settings.ipv6_address_mode)
def test_all(self): sub_settings = SubnetSettings(name='foo-subnet', cidr='10.0.0.0/24') settings = NetworkSettings(name='foo', admin_state_up=False, shared=True, project_name='bar', external=True, network_type='vlan', physical_network='phy', segmentation_id=2366, subnet_settings=[sub_settings]) self.assertEqual('foo', settings.name) self.assertFalse(settings.admin_state_up) self.assertTrue(settings.shared) self.assertEqual('bar', settings.project_name) self.assertTrue(settings.external) self.assertEqual('vlan', settings.network_type) self.assertEqual('phy', settings.physical_network) self.assertEqual(2366, settings.segmentation_id) self.assertEqual(1, len(settings.subnet_settings)) self.assertEqual('foo-subnet', settings.subnet_settings[0].name)
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
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_config_with_name_only(self): with self.assertRaises(SubnetConfigError): SubnetSettings(**{'name': 'foo'})
def test_name_only(self): with self.assertRaises(SubnetConfigError): SubnetSettings(name='foo')
def test_empty_config(self): with self.assertRaises(SubnetConfigError): SubnetSettings(**dict())
def test_no_params(self): with self.assertRaises(SubnetConfigError): SubnetSettings()
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') project_creator = deploy_utils.create_project( self.os_creds, ProjectSettings(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, UserSettings( name=CONST.__getattribute__('tempest_identity_user_name'), 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, NetworkSettings( name=CONST.__getattribute__('tempest_private_net_name'), project_name=project_name, subnet_settings=[ SubnetSettings(name=CONST.__getattribute__( 'tempest_private_subnet_name'), 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 if (CONST.__getattribute__('tempest_use_custom_images') or use_custom_images): logger.debug("Creating image for Tempest suite") image_base_name = CONST.__getattribute__('openstack_image_name') 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') 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') 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, FlavorSettings( name=CONST.__getattribute__('openstack_flavor_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) 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 flavor_creator_alt = OpenStackFlavor( self.os_creds, FlavorSettings( name=CONST.__getattribute__('openstack_flavor_name_alt'), 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