X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=functest%2Fopnfv_tests%2Fvnf%2Fims%2Forchestra_openims.py;h=c35ec8c1801e715ac26e9bd3d8a62f6275b88486;hb=edac6a883e0b80724140305258649b4891a2d14c;hp=aae35146fe7dc2df5f281b22424e5cdc7d0ef612;hpb=ac2de4356604f81cff9c303f0af36601e8a330ea;p=functest.git diff --git a/functest/opnfv_tests/vnf/ims/orchestra_openims.py b/functest/opnfv_tests/vnf/ims/orchestra_openims.py index aae35146f..c35ec8c18 100644 --- a/functest/opnfv_tests/vnf/ims/orchestra_openims.py +++ b/functest/opnfv_tests/vnf/ims/orchestra_openims.py @@ -17,31 +17,28 @@ import time import pkg_resources import yaml - -from snaps.openstack.create_image import OpenStackImage, ImageSettings -from snaps.openstack.create_flavor import OpenStackFlavor, FlavorSettings -from snaps.openstack.create_security_group import ( - OpenStackSecurityGroup, - SecurityGroupSettings, - SecurityGroupRuleSettings, - Direction, - Protocol) -from snaps.openstack.create_network import ( - OpenStackNetwork, - NetworkSettings, - SubnetSettings, - PortSettings) -from snaps.openstack.create_router import OpenStackRouter, RouterSettings -from snaps.openstack.create_instance import ( - VmInstanceSettings, OpenStackVmInstance) -from functest.opnfv_tests.openstack.snaps import snaps_utils - import functest.core.vnf as vnf import functest.utils.openstack_utils as os_utils from functest.utils.constants import CONST from org.openbaton.cli.errors.errors import NfvoException from org.openbaton.cli.agents.agents import MainAgent +from snaps.config.flavor import FlavorConfig +from snaps.config.image import ImageConfig +from snaps.config.network import NetworkConfig, PortConfig, SubnetConfig +from snaps.config.router import RouterConfig +from snaps.config.security_group import ( + Direction, Protocol, SecurityGroupConfig, SecurityGroupRuleConfig) +from snaps.config.vm_inst import VmInstanceConfig +from snaps.openstack.utils import keystone_utils +from snaps.openstack.create_image import OpenStackImage +from snaps.openstack.create_flavor import OpenStackFlavor +from snaps.openstack.create_security_group import OpenStackSecurityGroup +from snaps.openstack.create_network import OpenStackNetwork +from snaps.openstack.create_router import OpenStackRouter +from snaps.openstack.create_instance import OpenStackVmInstance + +from functest.opnfv_tests.openstack.snaps import snaps_utils __author__ = "Pauls, Michael " @@ -130,6 +127,8 @@ def get_userdata(orchestrator=dict): orchestrator['gvnfm']['userdata']['url']) userdata += "sed -i '113i"'\ \ \ \ '"sleep 60' " \ "/etc/openbaton/openbaton-vnfm-generic-user-data.sh\n" + userdata += ("sed -i s/nfvo.marketplace.port=8082/nfvo.marketplace." + "port=8080/g /etc/openbaton/openbaton-nfvo.properties\n") userdata += "echo \"Starting NFVO\"\n" userdata += "service openbaton-nfvo restart\n" userdata += "echo \"Starting Generic VNFM\"\n" @@ -141,25 +140,25 @@ def get_userdata(orchestrator=dict): class OpenImsVnf(vnf.VnfOnBoarding): """OpenIMS VNF deployed with openBaton orchestrator""" - logger = logging.getLogger(__name__) + # logger = logging.getLogger(__name__) def __init__(self, **kwargs): if "case_name" not in kwargs: kwargs["case_name"] = "orchestra_openims" super(OpenImsVnf, self).__init__(**kwargs) - # self.logger = logging.getLogger("functest.ci.run_tests.orchestra") + self.logger = logging.getLogger("functest.ci.run_tests.orchestra") self.logger.info("kwargs %s", (kwargs)) self.case_dir = pkg_resources.resource_filename( 'functest', 'opnfv_tests/vnf/ims/') - self.data_dir = CONST.__getattribute__('dir_ims_data') - self.test_dir = CONST.__getattribute__('dir_repo_vims_test') + self.data_dir = getattr(CONST, 'dir_ims_data') + self.test_dir = getattr(CONST, 'dir_repo_vims_test') self.created_resources = [] self.logger.info("%s VNF onboarding test starting", self.case_name) try: - self.config = CONST.__getattribute__( - 'vnf_{}_config'.format(self.case_name)) + self.config = getattr( + CONST, 'vnf_{}_config'.format(self.case_name)) except BaseException: raise Exception("Orchestra VNF config file not found") config_file = self.case_dir + self.config @@ -202,12 +201,15 @@ class OpenImsVnf(vnf.VnfOnBoarding): """Prepare testscase (Additional pre-configuration steps).""" super(OpenImsVnf, self).prepare() + public_auth_url = keystone_utils.get_endpoint( + self.snaps_creds, 'identity') + self.logger.info("Additional pre-configuration steps") self.creds = { - "tenant": self.tenant_name, - "username": self.tenant_name, - "password": self.tenant_name, - "auth_url": os_utils.get_credentials()['auth_url'] + "tenant": self.snaps_creds.project_name, + "username": self.snaps_creds.username, + "password": self.snaps_creds.password, + "auth_url": public_auth_url } self.prepare_images() self.prepare_flavor() @@ -223,11 +225,11 @@ class OpenImsVnf(vnf.VnfOnBoarding): if image_file and image_name: image = OpenStackImage( self.snaps_creds, - ImageSettings(name=image_name, - image_user='cloud', - img_format='qcow2', - image_file=image_file, - public=True)) + ImageConfig(name=image_name, + image_user='cloud', + img_format='qcow2', + image_file=image_file, + public=True)) image.create() # self.created_resources.append(image); @@ -237,61 +239,36 @@ class OpenImsVnf(vnf.VnfOnBoarding): "Creating security group for Open Baton if not yet existing...") sg_rules = list() sg_rules.append( - SecurityGroupRuleSettings( + SecurityGroupRuleConfig( sec_grp_name="orchestra-sec-group-allowall", direction=Direction.ingress, protocol=Protocol.tcp, port_range_min=1, port_range_max=65535)) sg_rules.append( - SecurityGroupRuleSettings( + SecurityGroupRuleConfig( sec_grp_name="orchestra-sec-group-allowall", direction=Direction.egress, protocol=Protocol.tcp, port_range_min=1, port_range_max=65535)) sg_rules.append( - SecurityGroupRuleSettings( + SecurityGroupRuleConfig( sec_grp_name="orchestra-sec-group-allowall", direction=Direction.ingress, protocol=Protocol.udp, port_range_min=1, port_range_max=65535)) sg_rules.append( - SecurityGroupRuleSettings( + SecurityGroupRuleConfig( sec_grp_name="orchestra-sec-group-allowall", direction=Direction.egress, protocol=Protocol.udp, port_range_min=1, port_range_max=65535)) - sg_rules.append( - SecurityGroupRuleSettings( - sec_grp_name="orchestra-sec-group-allowall", - direction=Direction.ingress, - protocol=Protocol.icmp)) - sg_rules.append( - SecurityGroupRuleSettings( - sec_grp_name="orchestra-sec-group-allowall", - direction=Direction.egress, - protocol=Protocol.icmp)) - # sg_rules.append( - # SecurityGroupRuleSettings( - # sec_grp_name="orchestra-sec-group-allowall", - # direction=Direction.ingress, - # protocol=Protocol.icmp, - # port_range_min=-1, - # port_range_max=-1)) - # sg_rules.append( - # SecurityGroupRuleSettings( - # sec_grp_name="orchestra-sec-group-allowall", - # direction=Direction.egress, - # protocol=Protocol.icmp, - # port_range_min=-1, - # port_range_max=-1)) - security_group = OpenStackSecurityGroup( self.snaps_creds, - SecurityGroupSettings( + SecurityGroupConfig( name="orchestra-sec-group-allowall", rule_settings=sg_rules)) @@ -306,7 +283,7 @@ class OpenImsVnf(vnf.VnfOnBoarding): self.logger.info( "Create Flavor for Open Baton NFVO if not yet existing") - flavor_settings = FlavorSettings( + flavor_settings = FlavorConfig( name=self.mano['requirements']['flavor']['name'], ram=self.mano['requirements']['flavor']['ram_min'], disk=self.mano['requirements']['flavor']['disk'], @@ -322,11 +299,11 @@ class OpenImsVnf(vnf.VnfOnBoarding): """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( + subnet_settings = SubnetConfig( name='%s_subnet' % self.case_name, cidr="192.168.100.0/24") - network_settings = NetworkSettings( + network_settings = NetworkConfig( name='%s_net' % self.case_name, subnet_settings=[subnet_settings]) @@ -341,7 +318,7 @@ class OpenImsVnf(vnf.VnfOnBoarding): self.created_resources.append(orchestra_network) orchestra_router = OpenStackRouter( self.snaps_creds, - RouterSettings( + RouterConfig( name='%s_router' % self.case_name, external_gateway=self.mano['details']['external_net_name'], @@ -444,21 +421,21 @@ class OpenImsVnf(vnf.VnfOnBoarding): self.mano['details']['network']['id']) self.logger.debug("userdata: %s\n", userdata) # setting up image - image_settings = ImageSettings( + image_settings = ImageConfig( name=self.mano['requirements']['image'], image_user='ubuntu', exists=True) # setting up port - port_settings = PortSettings( + port_settings = PortConfig( name='%s_port' % self.case_name, network_name=self.mano['details']['network']['name']) # build configuration of vm - orchestra_settings = VmInstanceSettings( + 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=userdata) + userdata=str(userdata)) orchestra_vm = OpenStackVmInstance(self.snaps_creds, orchestra_settings, image_settings) @@ -486,18 +463,18 @@ class OpenImsVnf(vnf.VnfOnBoarding): self.logger.info("Waiting for Open Baton NFVO to be up and running...") timeout = 0 - while timeout < 200: + 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 * 5)) - time.sleep(5) + (timeout * 60)) + time.sleep(60) timeout += 1 - if timeout >= 200: + if timeout >= 20: duration = time.time() - start_time self.details["orchestrator"].update( status='FAIL', duration=duration) @@ -525,7 +502,7 @@ class OpenImsVnf(vnf.VnfOnBoarding): self.logger.info( "Create %s Flavor if not existing", self.vnf['name']) - flavor_settings = FlavorSettings( + flavor_settings = FlavorConfig( name=self.vnf['requirements']['flavor']['name'], ram=self.vnf['requirements']['flavor']['ram_min'], disk=self.vnf['requirements']['flavor']['disk'], @@ -590,13 +567,13 @@ class OpenImsVnf(vnf.VnfOnBoarding): 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) + self.logger.info("NSR is not yet ACTIVE... (%ss)", 60 * timeout) + if timeout == 30: + self.logger.error("INACTIVE NSR after %s sec..", 60 * timeout) duration = time.time() - start_time self.details["vnf"].update(status='FAIL', duration=duration) return False - time.sleep(5) + time.sleep(60) self.mano['details']['nsr'] = json.loads( nsr_agent.find(self.mano['details']['nsr'].get('id'))) @@ -684,8 +661,6 @@ class OpenImsVnf(vnf.VnfOnBoarding): time.sleep(60) else: self.logger.info("No need to terminate the VNF...") - # os_utils.delete_instance(nova_client=os_utils.get_nova_client(), - # instance_id=self.mano_instance_id) except (NfvoException, KeyError) as exc: self.logger.error('Unexpected error cleaning - %s', exc) @@ -697,13 +672,13 @@ class OpenImsVnf(vnf.VnfOnBoarding): port_name='%s_port' % self.case_name) snaps_utils.neutron_utils.delete_port(neutron_client, port) time.sleep(10) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except self.logger.error('Unexpected error cleaning - %s', exc) try: self.logger.info("Deleting Open Baton Floating IP...") snaps_utils.neutron_utils.delete_floating_ip( neutron_client, self.mano['details']['fip']) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except self.logger.error('Unexpected error cleaning - %s', exc) for resource in reversed(self.created_resources):