示例#1
0
 def test_config_all(self):
     metadata = {'foo': 'bar'}
     settings = FlavorSettings(
         **{
             'name': 'foo',
             'flavor_id': 'bar',
             'ram': 1,
             'disk': 2,
             'vcpus': 3,
             'ephemeral': 4,
             'swap': 5,
             'rxtx_factor': 6.0,
             'is_public': False,
             'metadata': metadata
         })
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.flavor_id)
     self.assertEqual(1, settings.ram)
     self.assertEqual(2, settings.disk)
     self.assertEqual(3, settings.vcpus)
     self.assertEqual(4, settings.ephemeral)
     self.assertEqual(5, settings.swap)
     self.assertEqual(6.0, settings.rxtx_factor)
     self.assertEqual(False, settings.is_public)
     self.assertEqual(metadata, settings.metadata)
示例#2
0
 def test_is_pub_string(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings(name='foo',
                        ram=1,
                        disk=2,
                        vcpus=3,
                        ephemeral=4,
                        swap=5,
                        rxtx_factor=6.0,
                        is_public='bar')
示例#3
0
 def test_ram_float(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings(name='foo',
                        ram=1.5,
                        disk=2,
                        vcpus=3,
                        ephemeral=4,
                        swap=5,
                        rxtx_factor=6.0,
                        is_public=False)
示例#4
0
 def test_name_ram_disk_vcpus_only(self):
     settings = FlavorSettings(name='foo', ram=1, disk=2, vcpus=3)
     self.assertEqual('foo', settings.name)
     self.assertEqual('auto', settings.flavor_id)
     self.assertEqual(1, settings.ram)
     self.assertEqual(2, settings.disk)
     self.assertEqual(3, settings.vcpus)
     self.assertEqual(0, settings.ephemeral)
     self.assertEqual(0, settings.swap)
     self.assertEqual(1.0, settings.rxtx_factor)
     self.assertEqual(True, settings.is_public)
     self.assertEqual(None, settings.metadata)
示例#5
0
    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.publish_archive(descriptor.get('url'),
                                              descriptor.get('name'),
                                              descriptor.get('file_name'))

        self.__logger.info("Get or create flavor for all clearwater vm")
        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_creator.create()
        self.created_object.append(flavor_creator)

        self.vnf['inputs'].update(dict(
            flavor_id=self.vnf['requirements']['flavor']['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=600)

        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
示例#6
0
 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 = FlavorSettings(
         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")
     if status == 0:
         instances = os_utils.get_instances(self.nova_client)
         for items in instances:
             metadata = get_instance_metadata(self.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(
                     self.neutron_client, sec_group)
                 break
         self.__logger.info("Adding Security group rule....")
         os_utils.create_secgroup_rule(self.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
示例#7
0
 def test_config_ram_float(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings(
             config={
                 'name': 'foo',
                 'ram': 1.5,
                 'disk': 2,
                 'vcpus': 3,
                 'ephemeral': 4,
                 'swap': 5,
                 'rxtx_factor': 6.0,
                 'is_public': False
             })
示例#8
0
    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
示例#10
0
 def test_config_with_name_ram_disk_vcpus_only(self):
     settings = FlavorSettings(**{
         'name': 'foo',
         'ram': 1,
         'disk': 2,
         'vcpus': 3
     })
     self.assertEqual('foo', settings.name)
     self.assertEqual('auto', settings.flavor_id)
     self.assertEqual(1, settings.ram)
     self.assertEqual(2, settings.disk)
     self.assertEqual(3, settings.vcpus)
     self.assertEqual(0, settings.ephemeral)
     self.assertEqual(0, settings.swap)
     self.assertEqual(1.0, settings.rxtx_factor)
     self.assertEqual(True, settings.is_public)
     self.assertEqual(None, settings.metadata)
示例#11
0
 def test_all(self):
     metadata = {'foo': 'bar'}
     settings = FlavorSettings(name='foo',
                               flavor_id='bar',
                               ram=1,
                               disk=2,
                               vcpus=3,
                               ephemeral=4,
                               swap=5,
                               rxtx_factor=6.0,
                               is_public=False,
                               metadata=metadata)
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.flavor_id)
     self.assertEqual(1, settings.ram)
     self.assertEqual(2, settings.disk)
     self.assertEqual(3, settings.vcpus)
     self.assertEqual(4, settings.ephemeral)
     self.assertEqual(5, settings.swap)
     self.assertEqual(6.0, settings.rxtx_factor)
     self.assertEqual(False, settings.is_public)
     self.assertEqual(metadata, settings.metadata)
示例#12
0
    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
示例#13
0
    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 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
示例#16
0
 def test_config_with_name_ram_disk_only(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings(config={'name': 'foo', 'ram': 1, 'disk': 1})
示例#17
0
 def test_name_ram_disk_only(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings(name='foo', ram=1, disk=1)
示例#18
0
 def test_config_with_name_only(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings(config={'name': 'foo'})
    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
示例#20
0
 def test_name_only(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings(name='foo')
示例#21
0
 def test_no_params(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings()
示例#22
0
 def test_empty_config(self):
     with self.assertRaises(FlavorConfigError):
         FlavorSettings(config=dict())