def test_assign_floatingip_to_vdu(self):
        vnfd_file = 'sample_tosca_assign_floatingip_to_vdu.yaml'
        vnf_name = 'Assign Floating IP to VDU'
        values_str = read_file(vnfd_file)
        template = yaml.safe_load(values_str)
        vnf_arg = {'vnf': {'vnfd_template': template, 'name': vnf_name}}
        self.connect_public_and_private_nw_with_router()
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        vnf_id = vnf_instance['vnf']['id']
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
                        constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.addCleanup(self.client.delete_vnf, vnf_id)
        self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        vnf_show_out = self.client.show_vnf(vnf_id)['vnf']
        self.assertIsNotNone(vnf_show_out['mgmt_ip_address'])

        stack_id = vnf_show_out['instance_id']
        fip_res = self.get_heat_stack_resource(stack_id, 'FIP1')
        floating_ip_address = fip_res['attributes']['floating_ip_address']
        self.assertIsNotNone(floating_ip_address)
        fip_port_id = fip_res['attributes']['port_id']
        port_res = self.get_heat_stack_resource(stack_id, 'CP1')
        port_id = port_res['attributes']['id']
        self.assertEqual(fip_port_id, port_id)
Example #2
0
    def test_assign_floatingip_to_vdu(self):
        vnfd_file = 'sample_tosca_assign_floatingip_to_vdu.yaml'
        vnf_name = 'Assign Floating IP to VDU'
        values_str = read_file(vnfd_file)
        template = yaml.safe_load(values_str)
        vnf_arg = {'vnf': {'vnfd_template': template, 'name': vnf_name}}
        self.connect_public_and_private_nw_with_router()
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        vnf_id = vnf_instance['vnf']['id']
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
                        constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.addCleanup(self.client.delete_vnf, vnf_id)
        self.wait_until_vnf_active(vnf_id, constants.VNF_CIRROS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        vnf_show_out = self.client.show_vnf(vnf_id)['vnf']
        self.assertIsNotNone(vnf_show_out['mgmt_ip_address'])

        stack_id = vnf_show_out['instance_id']
        fip_res = self.get_heat_stack_resource(stack_id, 'FIP1')
        floating_ip_address = fip_res['attributes']['floating_ip_address']
        self.assertIsNotNone(floating_ip_address)
        fip_port_id = fip_res['attributes']['port_id']
        port_res = self.get_heat_stack_resource(stack_id, 'CP1')
        port_id = port_res['attributes']['id']
        self.assertEqual(fip_port_id, port_id)
Example #3
0
    def _test_vnf_with_monitoring(self, vnfd_file, vnf_name):
        data = dict()
        data['tosca'] = read_file(vnfd_file)
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        # Verify vnf goes from ACTIVE->DEAD->ACTIVE states
        self.verify_vnf_restart(vnfd_instance, vnf_instance)

        # Delete vnf_instance with vnf_id
        vnf_id = vnf_instance['vnf']['id']
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, ("Failed to delete vnf %s after the monitor test" %
                           vnf_id)

        # Delete vnfd_instance
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, ("Failed to delete vnfd %s after the monitor test" %
                           vnfd_id)
Example #4
0
    def _test_vnf_with_monitoring(self, vnfd_file, vnf_name):
        data = dict()
        data['tosca'] = read_file(vnfd_file)
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        # Verify vnf goes from ACTIVE->DEAD->ACTIVE states
        self.verify_vnf_restart(vnfd_instance, vnf_instance)

        # Delete vnf_instance with vnf_id
        vnf_id = vnf_instance['vnf']['id']
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, ("Failed to delete vnf %s after the monitor test" %
                           vnf_id)

        # Delete vnfd_instance
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, ("Failed to delete vnfd %s after the monitor test" %
                           vnfd_id)
Example #5
0
    def _test_vnf_create(self, vnfd_instance, vnf_name, vnf_value_file):
        # Create the vnf with values
        vnfd_id = vnfd_instance['vnfd']['id']
        values_str = read_file(vnf_value_file)

        # Create vnf with values file
        vnf_dict = dict()
        vnf_dict = {
            'vnf': {
                'vnfd_id': vnfd_id,
                'name': vnf_name,
                'attributes': {
                    'param_values': values_str
                }
            }
        }
        vnf_instance = self.client.create_vnf(body=vnf_dict)

        self.validate_vnf_instance(vnfd_instance, vnf_instance)
        vnf_id = vnf_instance['vnf']['id']
        vnf_current_status = self.wait_until_vnf_active(
            vnf_id, constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertEqual('ACTIVE', vnf_current_status)
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
        vnf_instance = self.client.show_vnf(vnf_id)

        # Verify values dictionary is same as param values from vnf_show
        input_dict = yaml.load(values_str)
        param_values = vnf_instance['vnf']['attributes']['param_values']
        param_values_dict = yaml.load(param_values)
        self.assertEqual(input_dict, param_values_dict)
        return vnf_instance
Example #6
0
 def heatclient(cls):
     data = yaml.load(read_file('local-vim.yaml'))
     data['auth_url'] = data['auth_url'] + '/v3'
     domain_name = data.pop('domain_name')
     data['user_domain_name'] = domain_name
     data['project_domain_name'] = domain_name
     return clients.OpenstackClients(auth_attr=data).heat
Example #7
0
    def _test_vnf_with_monitoring(self, vnfd_file, vnf_name):
        data = dict()
        data["tosca"] = read_file(vnfd_file)
        toscal = data["tosca"]
        tosca_arg = {"vnfd": {"attributes": {"vnfd": toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance["vnfd"]["id"]
        vnf_arg = {"vnf": {"vnfd_id": vnfd_id, "name": vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        # Verify vnf goes from ACTIVE->DEAD->ACTIVE states
        self.verify_vnf_restart(vnfd_instance, vnf_instance)

        # Delete vnf_instance with vnf_id
        vnf_id = vnf_instance["vnf"]["id"]
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "Failed to delete vnf %s after the monitor test" % vnf_id

        # Delete vnfd_instance
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "Failed to delete vnfd %s after the monitor test" % vnfd_id
Example #8
0
    def _generate_vim_data(self, vim_file, name, description, vim_type,
                           version=None):

        data = yaml.safe_load(read_file(vim_file))
        password = data['password']
        username = data['username']
        project_name = data['project_name']
        auth_url = data['auth_url']
        if version:
            if ('v2' == version and (not auth_url.endswith("/v2.0") or
                                     not auth_url.endswith("/v2.0/"))):
                auth_url += "/v2.0"
            elif (not auth_url.endswith("/v3") or
                  not auth_url.endswith("/v3/")):
                auth_url += "/v3"
        domain_name = data.get('domain_name', None)
        vim_arg = {'vim': {'name': name, 'description': description,
                           'type': vim_type,
                           'auth_url': auth_url,
                           'auth_cred': {'username': username,
                                         'password': password,
                                         'user_domain_name': domain_name},
                           'vim_project': {'name': project_name,
                                           'project_domain_name':
                                               domain_name},
                           'is_default': False}}
        return data, vim_arg
Example #9
0
    def vnfd_and_vnf_create(self, vnfd_file, vnf_name):
        input_yaml = read_file(vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)
        tosca_arg = {
            'vnfd': {
                'name': vnf_name,
                'attributes': {
                    'vnfd': tosca_dict
                }
            }
        }

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        self.addCleanup(self.client.delete_vnfd, vnfd_id)

        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        return vnfd_instance, vnf_instance, tosca_dict
Example #10
0
    def _test_vnf_with_monitoring(self, vnfd_file, vnf_name):
        data = dict()
        data['tosca'] = read_file(vnfd_file)
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'name': vnf_name,
                              'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        # Verify vnf goes from ACTIVE->DEAD->ACTIVE states
        self.verify_vnf_restart(vnfd_instance, vnf_instance)

        # Delete vnf_instance with vnf_id
        vnf_id = vnf_instance['vnf']['id']
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, ("Failed to delete vnf %s after the monitor test" %
                           vnf_id)

        # Verify VNF monitor events captured for states, ACTIVE and DEAD
        vnf_state_list = [evt_constants.ACTIVE, evt_constants.DEAD]
        self.verify_vnf_monitor_events(vnf_id, vnf_state_list)

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
            constants.VNF_CIRROS_DELETE_TIMEOUT)
Example #11
0
    def test_create_delete_vnf_tosca_no_monitoring(self):
        data = dict()
        data['tosca'] = read_file('sample-tosca-vnfd.yaml')
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_name = 'test_tosca_vnf_with_cirros_no_monitoring'
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        vnf_current_status = self.wait_until_vnf_active(
            vnf_id, constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertEqual(vnf_current_status, 'ACTIVE')
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
                        constants.VNF_CIRROS_DELETE_TIMEOUT)
Example #12
0
    def test_create_delete_vnf_tosca_no_monitoring(self):
        vnfd_name = 'tosca_vnfd_with_auto_image'
        input_yaml = read_file('sample-tosca-vnfd-image.yaml')
        tosca_dict = yaml.safe_load(input_yaml)
        tosca_arg = {'vnfd': {'name': vnfd_name, 'attributes': {'vnfd':
                                                                tosca_dict}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_name = 'tosca_vnf_with_auto_image'
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf'][
            'mgmt_ip_address'])

        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE,
            evt_constants.PENDING_CREATE, cnt=2)
        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)

        servers = self.novaclient().servers.list()
        vdu_server = None
        for server in servers:
            if 'VDU1_image_func' in server.name:
                vdu_server = server
                break
        self.assertIsNotNone(vdu_server)
        image_id = vdu_server.image["id"]
        nova_images = self.novaclient().images
        image = nova_images.get(image_id)
        self.assertIsNotNone(image)
        self.assertEqual(True, "VNFImage_image_func" in image.name)
        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        self.wait_until_vnf_delete(vnf_id,
                                   constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE,
                                    evt_constants.PENDING_DELETE, cnt=2)

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.assertRaises(exceptions.NotFound, nova_images.delete,
                          [image_id])
    def _test_create_list_delete_tosca_vnfd(self, tosca_vnfd_file, vnfd_name):
        input_yaml = read_file(tosca_vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)
        tosca_arg = {
            'vnfd': {
                'name': vnfd_name,
                'attributes': {
                    'vnfd': tosca_dict
                }
            }
        }
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        vnfds = self.client.list_vnfds().get('vnfds')
        self.assertIsNotNone(vnfds, "List of vnfds are Empty after Creation")

        vnfd_id = vnfd_instance['vnfd']['id']
        self.verify_vnfd_events(vnfd_id, evt_constants.RES_EVT_CREATE,
                                evt_constants.RES_EVT_ONBOARDED)

        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete failed"
        self.verify_vnfd_events(vnfd_id, evt_constants.RES_EVT_DELETE,
                                evt_constants.RES_EVT_NA_STATE)
Example #14
0
    def _test_create_delete_vim(self, vim_file, name, description, vim_type,
                                version=None):
        data = yaml.load(read_file(vim_file))

        password = data['password']
        username = data['username']
        project_name = data['project_name']
        auth_url = data['auth_url']

        vim_arg = {'vim': {'name': name, 'description': description,
                           'type': vim_type,
                           'auth_url': auth_url,
                           'auth_cred': {'username': username,
                                         'password': password},
                           'vim_project': {'name': project_name}}}

        # Register vim
        vim_res = self.client.create_vim(vim_arg)
        vim_obj = vim_res['vim']
        vim_id = vim_obj['id']
        self.verify_vim(vim_obj, data, name, description, version)

        # Read vim
        vim_show_res = self.client.show_vim(vim_id)
        self.verify_vim(vim_show_res['vim'], data, name, description, version)

        # Delete vim
        try:
            self.client.delete_vim(vim_id)
        except Exception:
            self.assertFalse(True, "Failed to delete vim %s" % vim_id)
Example #15
0
    def _test_vnf_create(self, vnfd_instance, vnf_name, vnf_value_file):
        # Create the vnf with values
        vnfd_id = vnfd_instance['vnfd']['id']
        values_str = read_file(vnf_value_file)

        # Create vnf with values file
        vnf_dict = dict()
        vnf_dict = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name,
                    'attributes': {'param_values': values_str}}}
        vnf_instance = self.client.create_vnf(body=vnf_dict)

        self.validate_vnf_instance(vnfd_instance, vnf_instance)
        vnf_id = vnf_instance['vnf']['id']
        vnf_current_status = self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertEqual('ACTIVE', vnf_current_status)
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
        vnf_instance = self.client.show_vnf(vnf_id)

        # Verify values dictionary is same as param values from vnf_show
        input_dict = yaml.load(values_str)
        param_values = vnf_instance['vnf']['attributes']['param_values']
        param_values_dict = yaml.load(param_values)
        self.assertEqual(input_dict, param_values_dict)
        return vnf_instance
Example #16
0
    def _test_create_list_delete_vnfd(self, vnfd_file):
        data = dict()
        data['tosca'] = read_file(vnfd_file)
        toscal = data['tosca']
        vnfd_name = 'sample_cirros_vnf'
        tosca_arg = {
            'vnfd': {
                'name': vnfd_name,
                'attributes': {
                    'vnfd': toscal
                }
            }
        }
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        vnfds = self.client.list_vnfds().get('vnfds')
        self.assertIsNotNone(vnfds, "List of vnfds are Empty after Creation")

        vnfd_id = vnfd_instance['vnfd']['id']

        self.verify_vnfd_events(
            vnfd_id, evt_constants.RES_EVT_CREATE,
            vnfd_instance['vnfd'][evt_constants.RES_EVT_CREATED_FLD])
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete failed"
        self.verify_vnfd_events(vnfd_id, evt_constants.RES_EVT_DELETE)
Example #17
0
 def heatclient(cls):
     data = yaml.safe_load(read_file('local-vim.yaml'))
     data['auth_url'] = data['auth_url'] + '/v3'
     domain_name = data.pop('domain_name')
     data['user_domain_name'] = domain_name
     data['project_domain_name'] = domain_name
     return clients.OpenstackClients(auth_attr=data).heat
Example #18
0
    def _test_create_delete_vnf(self, vnf_name, vnfd_name, vim_id=None):
        data = dict()
        data['tosca'] = read_file('sample-tosca-vnfd-no-monitor.yaml')
        toscal = data['tosca']
        tosca_arg = {
            'vnfd': {
                'name': vnfd_name,
                'attributes': {
                    'vnfd': toscal
                }
            }
        }

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        if vim_id:
            vnf_arg['vnf']['vim_id'] = vim_id
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(vnf_id, constants.VNF_CIRROS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
        if vim_id:
            self.assertEqual(vim_id, vnf_instance['vnf']['vim_id'])

        # Get vnf details when vnf is in active state
        vnf_details = self.client.list_vnf_resources(vnf_id)['resources'][0]
        self.assertIn('name', vnf_details)
        self.assertIn('id', vnf_details)
        self.assertIn('type', vnf_details)

        self.verify_vnf_crud_events(vnf_id,
                                    evt_constants.RES_EVT_CREATE,
                                    evt_constants.PENDING_CREATE,
                                    cnt=2)
        self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_CREATE,
                                    evt_constants.ACTIVE)

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        self.wait_until_vnf_delete(vnf_id, constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.verify_vnf_crud_events(vnf_id,
                                    evt_constants.RES_EVT_DELETE,
                                    evt_constants.PENDING_DELETE,
                                    cnt=2)

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
Example #19
0
    def _test_create_delete_vnf_events(self, vnf_name, vim_id=None):
        data = dict()
        data['tosca'] = read_file(
            'sample_cirros_vnf_no_monitoring.yaml')
        vnfd_name = 'sample_cirros_vnf_no_monitoring'
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'name': vnfd_name,
                     'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        if vim_id:
            vnf_arg['vnf']['vim_id'] = vim_id
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        vnf_current_status = self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertEqual('ACTIVE', vnf_current_status)
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
        if vim_id:
            self.assertEqual(vim_id, vnf_instance['vnf']['vim_id'])

        vnf_id = vnf_instance['vnf']['id']
        params = {'resource_id': vnf_id,
                  'event_type': evt_constants.RES_EVT_CREATE,
                  'timestamp': vnf_instance['vnf'][
                      evt_constants.RES_EVT_CREATED_FLD]}
        vnf_evt_list = self.client.list_vnf_events(params)

        self.assertIsNotNone(vnf_evt_list,
                             "List of vnfd events are Empty after Creation")

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        params = {'resource_id': vnf_id,
                  'event_type': evt_constants.RES_EVT_DELETE}
        vnf_evt_list = self.client.list_vnf_events(params)

        self.assertIsNotNone(vnf_evt_list,
                             "List of vnf events are Empty after Deletion")
        self.assertEqual(1, len(vnf_evt_list))

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
            constants.VNF_CIRROS_DELETE_TIMEOUT)
Example #20
0
    def test_create_delete_vnf_tosca_no_monitoring(self):
        vnfd_name = 'tosca_vnfd_with_auto_image'
        input_yaml = read_file('sample-tosca-vnfd-image.yaml')
        tosca_dict = yaml.safe_load(input_yaml)
        tosca_arg = {'vnfd': {'name': vnfd_name, 'attributes': {'vnfd':
                                                                tosca_dict}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_name = 'tosca_vnf_with_auto_image'
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])

        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE,
            evt_constants.PENDING_CREATE, cnt=2)
        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)

        servers = self.novaclient().servers.list()
        vdu_server = None
        for server in servers:
            if 'VDU1_image_func' in server.name:
                vdu_server = server
                break
        self.assertIsNotNone(vdu_server)
        image_id = vdu_server.image["id"]
        nova_images = self.novaclient().images
        image = nova_images.get(image_id)
        self.assertIsNotNone(image)
        self.assertEqual(True, "VNFImage_image_func" in image.name)
        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        self.wait_until_vnf_delete(vnf_id,
                                   constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE,
                                    evt_constants.PENDING_DELETE, cnt=2)

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.assertRaises(exceptions.NotFound, nova_images.delete,
                          [image_id])
Example #21
0
 def _test_create_nsd(self, tosca_nsd_file, nsd_name):
     input_yaml = read_file(tosca_nsd_file)
     tosca_dict = yaml.safe_load(input_yaml)
     tosca_arg = {'nsd': {'name': nsd_name,
                          'attributes': {'nsd': tosca_dict}}}
     nsd_instance = self.client.create_nsd(body=tosca_arg)
     self.assertIsNotNone(nsd_instance)
     return nsd_instance['nsd']['id']
Example #22
0
 def _test_create_nsd(self, tosca_nsd_file, nsd_name):
     input_yaml = read_file(tosca_nsd_file)
     tosca_dict = yaml.safe_load(input_yaml)
     tosca_arg = {'nsd': {'name': nsd_name,
                          'attributes': {'nsd': tosca_dict}}}
     nsd_instance = self.client.create_nsd(body=tosca_arg)
     self.assertIsNotNone(nsd_instance)
     return nsd_instance['nsd']['id']
Example #23
0
    def test_create_delete_vnf_with_multiple_vdus(self):
        data = dict()
        input_yaml = read_file('sample-vnfd-multi-vdu.yaml')
        data['tosca'] = input_yaml
        toscal = data['tosca']
        vnfd_name = 'sample-vnfd-multi-vdu'
        tosca_arg = {
            'vnfd': {
                'name': vnfd_name,
                'attributes': {
                    'vnfd': toscal
                }
            }
        }

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {
            'vnf': {
                'vnfd_id': vnfd_id,
                'name': "test_vnf_with_multiple_vdus"
            }
        }
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(vnf_id, constants.VNF_CIRROS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        self.assertEqual(
            self.client.show_vnf(vnf_id)['vnf']['status'], 'ACTIVE')
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        # Validate mgmt_url with input yaml file
        mgmt_url = self.client.show_vnf(vnf_id)['vnf']['mgmt_url']
        self.assertIsNotNone(mgmt_url)
        mgmt_dict = yaml.load(str(mgmt_url))

        input_dict = yaml.load(input_yaml)
        self.assertEqual(len(mgmt_dict.keys()), len(input_dict['vdus'].keys()))
        for vdu in input_dict['vdus'].keys():
            self.assertIsNotNone(mgmt_dict[vdu])
            self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu]))

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete of test_vnf_with_multiple_vdus failed"

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
                        constants.VNF_CIRROS_DELETE_TIMEOUT)
    def _test_create_vnf(self, vnfd_file, vnf_name,
                         template_source="onboarded"):
        input_yaml = read_file(vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)
        tosca_arg = {'vnfd': {'name': vnf_name,
                              'attributes': {'vnfd': tosca_dict}}}

        if template_source == "onboarded":
            # Create vnfd with tosca template
            vnfd_instance = self.client.create_vnfd(body=tosca_arg)
            self.assertIsNotNone(vnfd_instance)

            # Create vnf with vnfd_id
            vnfd_id = vnfd_instance['vnfd']['id']
            vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
            vnf_instance = self.client.create_vnf(body=vnf_arg)
            self.validate_vnf_instance(vnfd_instance, vnf_instance)

        if template_source == 'inline':
            # create vnf directly from template
            vnf_arg = {'vnf': {'vnfd_template': tosca_dict, 'name': vnf_name}}
            vnf_instance = self.client.create_vnf(body=vnf_arg)
            vnfd_id = vnf_instance['vnf']['vnfd_id']

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        vnf_show_out = self.client.show_vnf(vnf_id)['vnf']
        self.assertIsNotNone(vnf_show_out['mgmt_ip_address'])

        prop_dict = tosca_dict['topology_template']['node_templates'][
            'CP1']['properties']

        # Verify if ip_address is static, it is same as in show_vnf
        if prop_dict.get('ip_address'):
            mgmt_ip_address_input = prop_dict.get('ip_address')
            mgmt_info = yaml.safe_load(
                vnf_show_out['mgmt_ip_address'])
            self.assertEqual(mgmt_ip_address_input, mgmt_info['VDU1'])

        # Verify anti spoofing settings
        stack_id = vnf_show_out['instance_id']
        template_dict = tosca_dict['topology_template']['node_templates']
        for field in template_dict.keys():
            prop_dict = template_dict[field]['properties']
            if prop_dict.get('anti_spoofing_protection'):
                self.verify_antispoofing_in_stack(stack_id=stack_id,
                                                  resource_name=field)

        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE,
            evt_constants.PENDING_CREATE, cnt=2)
        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)
        return vnfd_id, vnf_id
    def test_create_delete_vnf_with_multiple_vdus(self):
        data = dict()
        input_yaml = read_file('sample-vnfd-multi-vdu.yaml')
        data['tosca'] = input_yaml
        toscal = data['tosca']
        vnfd_name = 'sample-vnfd-multi-vdu'
        tosca_arg = {'vnfd': {'name': vnfd_name,
                     'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name':
                           "test_vnf_with_multiple_vdus"}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(vnf_id,
                                   constants.VNF_CIRROS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        self.assertEqual('ACTIVE',
                         self.client.show_vnf(vnf_id)['vnf']['status'])
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE,
            vnf_instance['vnf'][evt_constants.RES_EVT_CREATED_FLD])
        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)

        # Validate mgmt_url with input yaml file
        mgmt_url = self.client.show_vnf(vnf_id)['vnf']['mgmt_url']
        self.assertIsNotNone(mgmt_url)
        mgmt_dict = yaml.load(str(mgmt_url))

        input_dict = yaml.load(input_yaml)
        self.assertEqual(len(input_dict['vdus'].keys()), len(mgmt_dict.keys()))
        for vdu in input_dict['vdus'].keys():
            self.assertIsNotNone(mgmt_dict[vdu])
            self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu]))

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete of test_vnf_with_multiple_vdus failed"

        self.wait_until_vnf_delete(vnf_id,
                                   constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE,
                                    evt_constants.PENDING_DELETE, cnt=2)

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
Example #26
0
    def _test_create_delete_vim(self,
                                vim_file,
                                name,
                                description,
                                vim_type,
                                version=None):
        data = yaml.safe_load(read_file(vim_file))

        password = data['password']
        username = data['username']
        project_name = data['project_name']
        auth_url = data['auth_url']
        if version:
            if ('v2' == version and (not auth_url.endswith("/v2.0")
                                     or not auth_url.endswith("/v2.0/"))):
                auth_url += "/v2.0"
            elif (not auth_url.endswith("/v3")
                  or not auth_url.endswith("/v3/")):
                auth_url += "/v3"
        domain_name = data.get('domain_name', None)
        vim_arg = {
            'vim': {
                'name': name,
                'description': description,
                'type': vim_type,
                'auth_url': auth_url,
                'auth_cred': {
                    'username': username,
                    'password': password,
                    'user_domain_name': domain_name
                },
                'vim_project': {
                    'name': project_name,
                    'project_domain_name': domain_name
                },
                'is_default': False
            }
        }

        # Register vim
        vim_res = self.client.create_vim(vim_arg)
        vim_obj = vim_res['vim']
        vim_id = vim_obj['id']
        self.verify_vim(vim_obj, data, name, description, version)
        self.verify_vim_events(vim_id, evt_constants.RES_EVT_CREATE)

        # Read vim
        vim_show_res = self.client.show_vim(vim_id)
        self.verify_vim(vim_show_res['vim'], data, name, description, version)

        # Delete vim
        try:
            self.client.delete_vim(vim_id)
        except Exception:
            self.assertFalse(True, "Failed to delete vim %s" % vim_id)
        self.verify_vim_events(vim_id, evt_constants.RES_EVT_DELETE)
    def test_create_delete_tosca_vnf_with_multiple_vdus(self):
        input_yaml = read_file("sample-tosca-vnfd-multi-vdu.yaml")
        tosca_dict = yaml.safe_load(input_yaml)
        vnfd_name = "sample-tosca-vnfd-multi-vdu"
        tosca_arg = {"vnfd": {"name": vnfd_name, "attributes": {"vnfd": tosca_dict}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance["vnfd"]["id"]
        vnf_arg = {"vnf": {"vnfd_id": vnfd_id, "name": "test_tosca_vnf_with_multiple_vdus"}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        vnf_id = vnf_instance["vnf"]["id"]
        self.wait_until_vnf_active(vnf_id, constants.VNF_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME)
        self.assertEqual("ACTIVE", self.client.show_vnf(vnf_id)["vnf"]["status"])
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        self.verify_vnf_crud_events(
            vnf_id,
            evt_constants.RES_EVT_CREATE,
            evt_constants.PENDING_CREATE,
            vnf_instance["vnf"][evt_constants.RES_EVT_CREATED_FLD],
        )
        self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)

        # Validate mgmt_url with input yaml file
        mgmt_url = self.client.show_vnf(vnf_id)["vnf"]["mgmt_url"]
        self.assertIsNotNone(mgmt_url)
        mgmt_dict = yaml.load(str(mgmt_url))

        input_dict = yaml.load(input_yaml)
        toscautils.updateimports(input_dict)

        tosca = tosca_template.ToscaTemplate(parsed_params={}, a_file=False, yaml_dict_tpl=input_dict)

        vdus = toscautils.findvdus(tosca)

        self.assertEqual(len(vdus), len(mgmt_dict.keys()))
        for vdu in vdus:
            self.assertIsNotNone(mgmt_dict[vdu.name])
            self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu.name]))

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete of test_vnf_with_multiple_vdus failed"

        self.wait_until_vnf_delete(vnf_id, constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE, evt_constants.PENDING_DELETE, cnt=2)

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
    def test_create_delete_tosca_vnf_with_multiple_vdus(self):
        data = dict()
        input_yaml = read_file('sample-tosca-vnfd-multi-vdu.yaml')
        data['tosca'] = input_yaml
        toscal = data['tosca']
        vnfd_name = 'sample-tosca-vnfd-multi-vdu'
        tosca_arg = {'vnfd': {'name': vnfd_name,
                              'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name':
                           "test_tosca_vnf_with_multiple_vdus"}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(vnf_id,
                                   constants.VNF_CIRROS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        self.assertEqual('ACTIVE',
                         self.client.show_vnf(vnf_id)['vnf']['status'])
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        # Validate mgmt_url with input yaml file
        mgmt_url = self.client.show_vnf(vnf_id)['vnf']['mgmt_url']
        self.assertIsNotNone(mgmt_url)
        mgmt_dict = yaml.load(str(mgmt_url))

        input_dict = yaml.load(input_yaml)
        toscautils.updateimports(input_dict)

        tosca = ToscaTemplate(parsed_params={}, a_file=False,
                          yaml_dict_tpl=input_dict)

        vdus = toscautils.findvdus(tosca)

        self.assertEqual(len(vdus), len(mgmt_dict.keys()))
        for vdu in vdus:
            self.assertIsNotNone(mgmt_dict[vdu.name])
            self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu.name]))

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete of test_vnf_with_multiple_vdus failed"

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
            constants.VNF_CIRROS_DELETE_TIMEOUT)
Example #29
0
    def _test_vnf_param_tosca_template(self, vnfd_file, vnfd_name, param_file,
                                       vnf_name):
        vnfd_instance = self._test_vnfd_create(vnfd_file, vnfd_name)

        # Get vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']

        # Add vnfd delete to cleanup job so that if vnf_instance fails to
        # create or update then it will be cleaned-up automatically
        # in tearDown()
        self.addCleanup(self.client.delete_vnfd, vnfd_id)

        # Create vnf instance
        values_str = read_file(param_file)
        values_dict = yaml.safe_load(values_str)
        vnf_instance, param_values_dict = self._test_vnf_create(
            vnfd_instance, vnf_name, values_dict)
        self.assertEqual(values_dict, param_values_dict)

        new_values_str = read_file('sample-tosca-vnf-update-values.yaml')
        new_values_dict = yaml.safe_load(new_values_str)
        vnf_param_values_dict, stack_parameters = self._test_vnf_update(
            vnf_instance, new_values_dict)
        for key, value in new_values_dict.items():
            if vnf_param_values_dict.get(key):
                self.assertEqual(value, vnf_param_values_dict[key])
            if stack_parameters.get(key):
                self.assertEqual(value, stack_parameters[key])

        self._test_vnf_delete(vnf_instance)
        vnf_id = vnf_instance['vnf']['id']
        self.verify_vnf_crud_events(vnf_id,
                                    evt_constants.RES_EVT_CREATE,
                                    evt_constants.PENDING_CREATE,
                                    cnt=2)
        self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_CREATE,
                                    evt_constants.ACTIVE)
        self.wait_until_vnf_delete(vnf_id, constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.verify_vnf_crud_events(vnf_id,
                                    evt_constants.RES_EVT_DELETE,
                                    evt_constants.PENDING_DELETE,
                                    cnt=2)
    def test_create_delete_tosca_vnf_with_multiple_vdus(self):
        data = dict()
        input_yaml = read_file('sample-tosca-vnfd-multi-vdu.yaml')
        data['tosca'] = input_yaml
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name':
                           "test_tosca_vnf_with_multiple_vdus"}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(vnf_id,
                                   constants.VNF_CIRROS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        self.assertEqual(self.client.show_vnf(vnf_id)['vnf']['status'],
                         'ACTIVE')
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        # Validate mgmt_url with input yaml file
        mgmt_url = self.client.show_vnf(vnf_id)['vnf']['mgmt_url']
        self.assertIsNotNone(mgmt_url)
        mgmt_dict = yaml.load(str(mgmt_url))

        input_dict = yaml.load(input_yaml)
        toscautils.updateimports(input_dict)

        tosca = ToscaTemplate(parsed_params={}, a_file=False,
                          yaml_dict_tpl=input_dict)

        vdus = toscautils.findvdus(tosca)

        self.assertEqual(len(mgmt_dict.keys()), len(vdus))
        for vdu in vdus:
            self.assertIsNotNone(mgmt_dict[vdu.name])
            self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu.name]))

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete of test_vnf_with_multiple_vdus failed"

        # Delete vnfd_instance
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete of sample-vnfd-multiple-vdus failed"
Example #31
0
    def vnfd_and_vnf_create_inline(self, vnfd_file, vnf_name):
        vnfd_instance = {}
        input_yaml = read_file(vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)

        # create vnf directly from template
        vnf_arg = {'vnf': {'vnfd_template': tosca_dict, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        return vnf_instance, tosca_dict
Example #32
0
    def _test_vnfd_create(self, vnfd_file):
        yaml_input = dict()
        yaml_input['tosca'] = read_file(vnfd_file)
        toscal = yaml_input['tosca']
        req_dict = {'vnfd': {'attributes': {'vnfd': toscal}}}

        # Create vnfd
        vnfd_instance = self.client.create_vnfd(body=req_dict)
        self.assertIsNotNone(vnfd_instance)
        vnfd_id = vnfd_instance['vnfd']['id']
        self.assertIsNotNone(vnfd_id)
        return vnfd_instance
Example #33
0
    def _test_create_tosca_vnfd(self, tosca_vnfd_file, vnfd_name):
        input_yaml = read_file(tosca_vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)
        tosca_arg = {'vnfd': {'name': vnfd_name,
                              'attributes': {'vnfd': tosca_dict}}}
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertEqual(vnfd_instance['vnfd']['name'], vnfd_name)
        self.assertIsNotNone(vnfd_instance)

        vnfds = self.client.list_vnfds().get('vnfds')
        self.assertIsNotNone(vnfds, "List of vnfds are Empty after Creation")
        return vnfd_instance['vnfd']['id']
Example #34
0
    def _test_create_vnf(self, vnfd_file, vnf_name):
        data = dict()
        values_str = read_file(vnfd_file)
        data['tosca'] = values_str
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'name': vnf_name,
                              'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        vnf_show_out = self.client.show_vnf(vnf_id)['vnf']
        self.assertIsNotNone(vnf_show_out['mgmt_url'])

        input_dict = yaml.load(values_str)
        prop_dict = input_dict['topology_template']['node_templates'][
            'CP1']['properties']

        # Verify if ip_address is static, it is same as in show_vnf
        if prop_dict.get('ip_address'):
            mgmt_url_input = prop_dict.get('ip_address')
            mgmt_info = yaml.load(
                vnf_show_out['mgmt_url'])
            self.assertEqual(mgmt_url_input, mgmt_info['VDU1'])

        # Verify anti spoofing settings
        stack_id = vnf_show_out['instance_id']
        template_dict = input_dict['topology_template']['node_templates']
        for field in template_dict.keys():
            prop_dict = template_dict[field]['properties']
            if prop_dict.get('anti_spoofing_protection'):
                self.verify_antispoofing_in_stack(stack_id=stack_id,
                                                  resource_name=field)

        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE,
            vnf_instance['vnf'][evt_constants.RES_EVT_CREATED_FLD])
        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)
        return vnfd_id, vnf_id
Example #35
0
    def _test_create_tosca_vnfd(self, tosca_vnfd_file, vnfd_name):
        input_yaml = read_file(tosca_vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)
        tosca_arg = {'vnfd': {'name': vnfd_name,
                              'attributes': {'vnfd': tosca_dict}}}
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertEqual(vnfd_instance['vnfd']['name'], vnfd_name)
        self.assertIsNotNone(vnfd_instance)

        vnfds = self.client.list_vnfds().get('vnfds')
        self.assertIsNotNone(vnfds, "List of vnfds are Empty after Creation")
        return vnfd_instance['vnfd']['id']
Example #36
0
    def _test_vnfd_create(self, vnfd_file):
        yaml_input = dict()
        yaml_input['tosca'] = read_file(vnfd_file)
        toscal = yaml_input['tosca']
        req_dict = {'vnfd': {'attributes': {'vnfd': toscal}}}

        # Create vnfd
        vnfd_instance = self.client.create_vnfd(body=req_dict)
        self.assertIsNotNone(vnfd_instance)
        vnfd_id = vnfd_instance['vnfd']['id']
        self.assertIsNotNone(vnfd_id)
        return vnfd_instance
Example #37
0
    def _test_create_delete_vnf(self, vnf_name, vnfd_name, vim_id=None):
        data = dict()
        data['tosca'] = read_file('sample_cirros_vnf_no_monitoring.yaml')
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'name': vnfd_name,
                     'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        if vim_id:
            vnf_arg['vnf']['vim_id'] = vim_id
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
        if vim_id:
            self.assertEqual(vim_id, vnf_instance['vnf']['vim_id'])

        # Get vnf details when vnf is in active state
        vnf_details = self.client.list_vnf_resources(vnf_id)['resources'][0]
        self.assertIn('name', vnf_details)
        self.assertIn('id', vnf_details)
        self.assertIn('type', vnf_details)

        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE,
            vnf_instance['vnf'][evt_constants.RES_EVT_CREATED_FLD])
        self.verify_vnf_crud_events(
            vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        self.wait_until_vnf_delete(vnf_id,
                                   constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE,
                                    evt_constants.PENDING_DELETE, cnt=2)

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
Example #38
0
    def test_create_delete_vnf_tosca_no_monitoring(self):
        data = dict()
        vnfd_name = 'tosca_vnfd_with_auto_flavor'
        data['tosca'] = read_file('sample-tosca-vnfd-flavor.yaml')
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'name': vnfd_name, 'attributes': {'vnfd':
                                                                toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnf_name = 'tosca_vnf_with_auto_flavor'
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        vnf_current_status = self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertEqual(vnf_current_status, 'ACTIVE')
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])

        servers = self.novaclient().servers.list()
        vdu_server = None
        for server in servers:
            if 'VDU1_flavor_func' in server.name:
                vdu_server = server
                break
        self.assertIsNotNone(vdu_server)
        flavor_id = server.flavor["id"]
        nova_flavors = self.novaclient().flavors
        flavor = nova_flavors.get(flavor_id)
        self.assertIsNotNone(flavor)
        self.assertEqual(True, "VDU1_flavor_func_flavor" in flavor.name)
        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
            constants.VNF_CIRROS_DELETE_TIMEOUT)
        self.assertRaises(exceptions.NotFound, nova_flavors.delete,
                          [flavor_id])
Example #39
0
    def _test_create_delete_ns(self, nsd_file, ns_name,
                               template_source='onboarded'):
        vnfd1_id = self._test_create_tosca_vnfd(
            'test-ns-vnfd1.yaml',
            'test-ns-vnfd1')
        vnfd2_id = self._test_create_tosca_vnfd(
            'test-ns-vnfd2.yaml',
            'test-ns-vnfd2')

        if template_source == 'onboarded':
            nsd_id = self._test_create_nsd(
                nsd_file,
                'test-ns-nsd')
            ns_arg = {'ns': {
                'nsd_id': nsd_id,
                'name': ns_name,
                'attributes': {"param_values": {
                    "nsd": {
                        "vl2_name": "net0",
                        "vl1_name": "net_mgmt"}}}}}
            ns_instance = self.client.create_ns(body=ns_arg)
            ns_id = ns_instance['ns']['id']

        if template_source == 'inline':
            input_yaml = read_file(nsd_file)
            template = yaml.safe_load(input_yaml)
            ns_arg = {'ns': {
                'name': ns_name,
                'attributes': {"param_values": {
                    "nsd": {
                        "vl2_name": "net0",
                        "vl1_name": "net_mgmt"}}},
                'nsd_template': template}}
            ns_instance = self.client.create_ns(body=ns_arg)
            ns_id = ns_instance['ns']['id']

        self._wait_until_ns_status(ns_id, 'ACTIVE',
                                   constants.NS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        ns_show_out = self.client.show_ns(ns_id)['ns']
        self.assertIsNotNone(ns_show_out['mgmt_urls'])

        try:
            self.client.delete_ns(ns_id)
        except Exception as e:
            print("Exception:", e)
            assert False, "ns Delete failed"
        if template_source == 'onboarded':
            self._wait_until_ns_delete(ns_id, constants.NS_DELETE_TIMEOUT)
            self._test_delete_nsd(nsd_id)
        self._test_delete_vnfd(vnfd1_id)
        self._test_delete_vnfd(vnfd2_id)
Example #40
0
    def test_create_delete_vnf_monitoring(self):
        data = dict()
        data['tosca'] = read_file(
            'sample_vnfd_no_param_monitoring_respawn.yaml')
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}

        #Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        ##Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_name = 'test_vnf_with_user_data_respawn'

        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}

        vnf_instance = self.client.create_vnf(body = vnf_arg)
        self.assertIsNotNone(vnf_instance)
        self.assertIsNotNone(vnf_instance['vnf']['id'])
        self.assertIsNotNone(vnf_instance['vnf']['instance_id'])
        self.assertEqual(vnf_instance['vnf']['vnfd_id'], vnfd_instance[
            'vnfd']['id'])

        ##Verify vnf is in ACTIVE state, then DEAD state and back ACTIVE again
        vnf_id = vnf_instance['vnf']['id']
        vnf_current_status = self.wait_until_vnf_active(vnf_id,
                                    constants.VNF_CIRROS_CREATE_TIMEOUT,
                                    constants.ACTIVE_SLEEP_TIME)

        self.assertEqual(vnf_current_status, 'ACTIVE')
        vnf_current_status = self.wait_until_vnf_dead(vnf_id,
                                    constants.VNF_CIRROS_DEAD_TIMEOUT,
                                    constants.DEAD_SLEEP_TIME)
        self.assertEqual(vnf_current_status, 'DEAD')
        vnf_current_status = self.wait_until_vnf_active(vnf_id,
                                    constants.VNF_CIRROS_CREATE_TIMEOUT,
                                    constants.ACTIVE_SLEEP_TIME)

        self.assertEqual(vnf_current_status, 'ACTIVE')

        ##Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed after the monitor test"

        ##Delete vnfd_instance
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete failed after the monitor test"
Example #41
0
    def _test_create_delete_ns(self, nsd_file, ns_name,
                               template_source='onboarded'):
        vnfd1_id = self._test_create_tosca_vnfd(
            'test-ns-vnfd1.yaml',
            'test-ns-vnfd1')
        vnfd2_id = self._test_create_tosca_vnfd(
            'test-ns-vnfd2.yaml',
            'test-ns-vnfd2')

        if template_source == 'onboarded':
            nsd_id = self._test_create_nsd(
                nsd_file,
                'test-ns-nsd')
            ns_arg = {'ns': {
                'nsd_id': nsd_id,
                'name': ns_name,
                'attributes': {"param_values": {
                    "nsd": {
                        "vl2_name": "net0",
                        "vl1_name": "net_mgmt"}}}}}
            ns_instance = self.client.create_ns(body=ns_arg)
            ns_id = ns_instance['ns']['id']

        if template_source == 'inline':
            input_yaml = read_file(nsd_file)
            template = yaml.safe_load(input_yaml)
            ns_arg = {'ns': {
                'name': ns_name,
                'attributes': {"param_values": {
                    "nsd": {
                        "vl2_name": "net0",
                        "vl1_name": "net_mgmt"}}},
                'nsd_template': template}}
            ns_instance = self.client.create_ns(body=ns_arg)
            ns_id = ns_instance['ns']['id']

        self._wait_until_ns_status(ns_id, 'ACTIVE',
                                   constants.NS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        ns_show_out = self.client.show_ns(ns_id)['ns']
        self.assertIsNotNone(ns_show_out['mgmt_ip_addresses'])

        try:
            self.client.delete_ns(ns_id)
        except Exception as e:
            print("Exception:", e)
            assert False, "ns Delete failed"
        if template_source == 'onboarded':
            self._wait_until_ns_delete(ns_id, constants.NS_DELETE_TIMEOUT)
            self._test_delete_nsd(nsd_id)
        self._test_delete_vnfd(vnfd1_id)
        self._test_delete_vnfd(vnfd2_id)
Example #42
0
 def test_vnf_param(self):
     vnfd_instance = self._test_vnfd_create('sample_cirros_vnf_param.yaml')
     values_str = read_file('sample_cirros_vnf_values.yaml')
     vnf_instance, param_values_dict = self._test_vnf_create(
         vnfd_instance, 'test_vnf_with_parameters', values_str)
     # Verify values dictionary is same as param values from vnf_show
     input_dict = yaml.safe_load(values_str)
     self.assertEqual(input_dict, param_values_dict)
     self._test_vnf_delete(vnf_instance)
     vnf_id = vnf_instance['vnf']['id']
     self.addCleanup(self.client.delete_vnfd, vnfd_instance['vnfd']['id'])
     self.addCleanup(self.wait_until_vnf_delete, vnf_id,
                     constants.VNF_CIRROS_DELETE_TIMEOUT)
Example #43
0
 def test_vnf_param_tosca_template(self):
     vnfd_instance = self._test_vnfd_create('sample-tosca-vnfd-param.yaml')
     values_str = read_file('sample-tosca-vnf-values.yaml')
     values_dict = yaml.safe_load(values_str)
     vnf_instance, param_values_dict = self._test_vnf_create(
         vnfd_instance, 'test_vnf_with_parameters_tosca_template',
         values_dict)
     self.assertEqual(values_dict, param_values_dict)
     self._test_vnf_delete(vnf_instance)
     vnf_id = vnf_instance['vnf']['id']
     self.addCleanup(self.client.delete_vnfd, vnfd_instance['vnfd']['id'])
     self.addCleanup(self.wait_until_vnf_delete, vnf_id,
                     constants.VNF_CIRROS_DELETE_TIMEOUT)
Example #44
0
    def _test_vnfd_create(self, vnfd_file, vnfd_name):
        yaml_input = read_file(vnfd_file)
        tosca_dict = yaml.safe_load(yaml_input)
        req_dict = {'vnfd': {'name': vnfd_name,
                    'attributes': {'vnfd': tosca_dict}}}

        # Create vnfd
        vnfd_instance = self.client.create_vnfd(body=req_dict)
        self.assertIsNotNone(vnfd_instance)
        vnfd_id = vnfd_instance['vnfd']['id']
        self.assertIsNotNone(vnfd_id)
        self.verify_vnfd_events(
            vnfd_id, evt_constants.RES_EVT_CREATE,
            evt_constants.RES_EVT_ONBOARDED)
        return vnfd_instance
Example #45
0
    def test_create_list_delete_vnfd(self):
        data = dict()
        data['tosca'] = read_file('sample_cirros_vnf.yaml')
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        vnfds = self.client.list_vnfds().get('vnfds')
        self.assertIsNotNone(vnfds, "List of vnfds are Empty after Creation")

        vnfd_id = vnfd_instance['vnfd']['id']
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete failed"
Example #46
0
    def test_create_list_delete_vnfd(self):
        data = dict()
        data['tosca'] = read_file('sample_cirros_vnf.yaml')
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        vnfds = self.client.list_vnfds().get('vnfds')
        self.assertIsNotNone(vnfds, "List of vnfds are Empty after Creation")

        vnfd_id = vnfd_instance['vnfd']['id']
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete failed"
Example #47
0
    def _test_create_delete_vim(self,
                                vim_file,
                                name,
                                description,
                                vim_type,
                                version=None):
        data = yaml.load(read_file(vim_file))

        password = data['password']
        username = data['username']
        project_name = data['project_name']
        auth_url = data['auth_url']
        domain_name = data.get('domain_name', None)
        vim_arg = {
            'vim': {
                'name': name,
                'description': description,
                'type': vim_type,
                'auth_url': auth_url,
                'auth_cred': {
                    'username': username,
                    'password': password,
                    'user_domain_name': domain_name
                },
                'vim_project': {
                    'name': project_name,
                    'project_domain_name': domain_name
                },
                'is_default': False
            }
        }

        # Register vim
        vim_res = self.client.create_vim(vim_arg)
        vim_obj = vim_res['vim']
        vim_id = vim_obj['id']
        self.verify_vim(vim_obj, data, name, description, version)

        # Read vim
        vim_show_res = self.client.show_vim(vim_id)
        self.verify_vim(vim_show_res['vim'], data, name, description, version)

        # Delete vim
        try:
            self.client.delete_vim(vim_id)
        except Exception:
            self.assertFalse(True, "Failed to delete vim %s" % vim_id)
    def test_create_delete_vnf_with_multiple_vdus(self):
        data = dict()
        input_yaml = read_file('sample-vnfd-multi-vdu.yaml')
        data['tosca'] = input_yaml
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}

        ##Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        ##Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name':
            "test_vnf_with_multiple_vdus"}}
        vnf_instance = self.client.create_vnf(body = vnf_arg)

        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(vnf_id,
                                   constants.VNF_CIRROS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        self.assertEqual(self.client.show_vnf(vnf_id)['vnf']['status'],
                         'ACTIVE')
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        ##Validate mgmt_url with input yaml file
        mgmt_url = self.client.show_vnf(vnf_id)['vnf']['mgmt_url']
        self.assertIsNotNone(mgmt_url)
        mgmt_dict = yaml.load(str(mgmt_url))

        input_dict = yaml.load(input_yaml)
        self.assertEqual(len(mgmt_dict.keys()), len(input_dict['vdus'].keys()))
        for vdu in input_dict['vdus'].keys():
            self.assertIsNotNone(mgmt_dict[vdu])
            self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu]))

        ##Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete of test_vnf_with_multiple_vdus failed"

        ##Delete vnfd_instance
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete of sample-vnfd-multiple-vdus failed"
    def _test_create_vnf(self, vnfd_file, vnf_name):
        input_yaml = read_file(vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)

        # create vnf directly from template
        vnf_arg = {'vnf': {'vnfd_template': tosca_dict, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        vnf_id = vnf_instance['vnf']['id']
        self.wait_until_vnf_active(vnf_id, constants.VNF_CIRROS_CREATE_TIMEOUT,
                                   constants.ACTIVE_SLEEP_TIME)
        vnf_show_out = self.client.show_vnf(vnf_id)['vnf']
        self.assertIsNotNone(vnf_show_out['mgmt_ip_address'])

        # Fetch mgmt ip of VNF
        mgmt_ip = eval(vnf_show_out['mgmt_ip_address'])['VDU1']

        return vnf_id, mgmt_ip
Example #50
0
    def _test_vnfd_create(self, vnfd_file, vnfd_name):
        yaml_input = read_file(vnfd_file)
        # TODO(anyone) remove this condition check once old templates
        # are deprecated
        if "tosca_definitions_version" in yaml_input:
            yaml_input = yaml.safe_load(yaml_input)
        req_dict = {'vnfd': {'name': vnfd_name,
                    'attributes': {'vnfd': yaml_input}}}

        # Create vnfd
        vnfd_instance = self.client.create_vnfd(body=req_dict)
        self.assertIsNotNone(vnfd_instance)
        vnfd_id = vnfd_instance['vnfd']['id']
        self.assertIsNotNone(vnfd_id)
        self.verify_vnfd_events(
            vnfd_id, evt_constants.RES_EVT_CREATE,
            vnfd_instance['vnfd'][evt_constants.RES_EVT_CREATED_FLD])
        return vnfd_instance
Example #51
0
    def _test_vnfd_create(self, vnfd_file, vnfd_name):
        yaml_input = read_file(vnfd_file)
        # TODO(anyone) remove this condition check once old templates
        # are deprecated
        if "tosca_definitions_version" in yaml_input:
            yaml_input = yaml.safe_load(yaml_input)
        req_dict = {'vnfd': {'name': vnfd_name,
                    'attributes': {'vnfd': yaml_input}}}

        # Create vnfd
        vnfd_instance = self.client.create_vnfd(body=req_dict)
        self.assertIsNotNone(vnfd_instance)
        vnfd_id = vnfd_instance['vnfd']['id']
        self.assertIsNotNone(vnfd_id)
        self.verify_vnfd_events(
            vnfd_id, evt_constants.RES_EVT_CREATE,
            vnfd_instance['vnfd'][evt_constants.RES_EVT_CREATED_FLD])
        return vnfd_instance
Example #52
0
    def _test_vnfd_create(self, vnfd_file, vnfd_name):
        yaml_input = read_file(vnfd_file)
        req_dict = {
            'vnfd': {
                'name': vnfd_name,
                'attributes': {
                    'vnfd': yaml_input
                }
            }
        }

        # Create vnfd
        vnfd_instance = self.client.create_vnfd(body=req_dict)
        self.assertIsNotNone(vnfd_instance)
        vnfd_id = vnfd_instance['vnfd']['id']
        self.assertIsNotNone(vnfd_id)
        self.verify_vnfd_events(vnfd_id, evt_constants.RES_EVT_CREATE,
                                evt_constants.RES_EVT_ONBOARDED)
        return vnfd_instance
Example #53
0
    def _vnfd_and_vnf_create(self, vnfd_file, vnf_name):
        input_yaml = read_file(vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)
        tosca_arg = {'vnfd': {'name': vnf_name,
                              'attributes': {'vnfd': tosca_dict}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        vnf_instance = self.client.create_vnf(body=vnf_arg)

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)

        return vnfd_instance, vnf_instance
Example #54
0
 def _test_vnf_param_tosca_template(self, vnfd_file, vnfd_name,
                                    param_file, vnf_name):
     vnfd_instance = self._test_vnfd_create(vnfd_file, vnfd_name)
     values_str = read_file(param_file)
     values_dict = yaml.safe_load(values_str)
     vnf_instance, param_values_dict = self._test_vnf_create(
         vnfd_instance, vnf_name, values_dict)
     self.assertEqual(values_dict, param_values_dict)
     self._test_vnf_delete(vnf_instance)
     vnf_id = vnf_instance['vnf']['id']
     self.verify_vnf_crud_events(
         vnf_id, evt_constants.RES_EVT_CREATE,
         evt_constants.PENDING_CREATE, cnt=2)
     self.verify_vnf_crud_events(
         vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)
     self.wait_until_vnf_delete(vnf_id,
                                constants.VNF_CIRROS_DELETE_TIMEOUT)
     self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE,
                                 evt_constants.PENDING_DELETE, cnt=2)
     self.addCleanup(self.client.delete_vnfd, vnfd_instance['vnfd']['id'])
Example #55
0
    def test_create_delete_vnf_no_monitoring(self):
        data = dict()
        data['tosca'] = read_file('sample_cirros_vnf_no_monitoring.yaml')
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}

        ##Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        ##Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name':
            "test_vnf_with_cirros_no_monitoring"}}
        vnf_instance = self.client.create_vnf(body = vnf_arg)
        self.assertIsNotNone(vnf_instance)
        self.assertIsNotNone(vnf_instance['vnf']['id'])
        self.assertIsNotNone(vnf_instance['vnf']['instance_id'])
        self.assertEqual(vnf_instance['vnf']['vnfd_id'], vnfd_instance[
            'vnfd']['id'])

        vnf_id = vnf_instance['vnf']['id']
        sleep_time = 5
        vnf_current_status = self.wait_until_vnf_active(vnf_id,
                                              VNF_CIRROS_CREATE_TIMEOUT,
                                                        sleep_time)
        self.assertEqual(vnf_current_status,
                         'ACTIVE')
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])

        ##Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        ##Delete vnfd_instance
        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete failed"
Example #56
0
    def _test_create_delete_vnf(self, vnf_name, vim_id=None):
        data = dict()
        data['tosca'] = read_file('sample_cirros_vnf_no_monitoring.yaml')
        vnfd_name = 'sample_cirros_vnf_no_monitoring'
        toscal = data['tosca']
        tosca_arg = {'vnfd': {'name': vnfd_name,
                     'attributes': {'vnfd': toscal}}}

        # Create vnfd with tosca template
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        # Create vnf with vnfd_id
        vnfd_id = vnfd_instance['vnfd']['id']
        vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
        if vim_id:
            vnf_arg['vnf']['vim_id'] = vim_id
        vnf_instance = self.client.create_vnf(body=vnf_arg)
        self.validate_vnf_instance(vnfd_instance, vnf_instance)

        vnf_id = vnf_instance['vnf']['id']
        vnf_current_status = self.wait_until_vnf_active(
            vnf_id,
            constants.VNF_CIRROS_CREATE_TIMEOUT,
            constants.ACTIVE_SLEEP_TIME)
        self.assertEqual('ACTIVE', vnf_current_status)
        self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
        if vim_id:
            self.assertEqual(vim_id, vnf_instance['vnf']['vim_id'])

        # Delete vnf_instance with vnf_id
        try:
            self.client.delete_vnf(vnf_id)
        except Exception:
            assert False, "vnf Delete failed"

        # Delete vnfd_instance
        self.addCleanup(self.client.delete_vnfd, vnfd_id)
        self.addCleanup(self.wait_until_vnf_delete, vnf_id,
            constants.VNF_CIRROS_DELETE_TIMEOUT)
    def _test_create_list_delete_tosca_vnfd(self, tosca_vnfd_file):
        input_yaml = read_file(tosca_vnfd_file)
        tosca_dict = yaml.safe_load(input_yaml)
        vnfd_name = 'sample-tosca-vnfd'
        tosca_arg = {'vnfd': {'name': vnfd_name,
                              'attributes': {'vnfd': tosca_dict}}}
        vnfd_instance = self.client.create_vnfd(body=tosca_arg)
        self.assertIsNotNone(vnfd_instance)

        vnfds = self.client.list_vnfds().get('vnfds')
        self.assertIsNotNone(vnfds, "List of vnfds are Empty after Creation")

        vnfd_id = vnfd_instance['vnfd']['id']
        self.verify_vnfd_events(
            vnfd_id, evt_constants.RES_EVT_CREATE,
            vnfd_instance['vnfd'][evt_constants.RES_EVT_CREATED_FLD])

        try:
            self.client.delete_vnfd(vnfd_id)
        except Exception:
            assert False, "vnfd Delete failed"
        self.verify_vnfd_events(vnfd_id, evt_constants.RES_EVT_DELETE)
Example #58
0
 def test_vnf_param_tosca_template(self):
     vnfd_name = 'cirros_vnfd_tosca_param'
     vnfd_instance = self._test_vnfd_create(
         'sample-tosca-vnfd-param.yaml', vnfd_name)
     values_str = read_file('sample-tosca-vnf-values.yaml')
     values_dict = yaml.safe_load(values_str)
     vnf_instance, param_values_dict = self._test_vnf_create(vnfd_instance,
                                 'test_vnf_with_parameters_tosca_template',
                                                             values_dict)
     self.assertEqual(values_dict, param_values_dict)
     self._test_vnf_delete(vnf_instance)
     vnf_id = vnf_instance['vnf']['id']
     self.verify_vnf_crud_events(
         vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE,
         vnf_instance['vnf'][evt_constants.RES_EVT_CREATED_FLD])
     self.verify_vnf_crud_events(
         vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)
     self.wait_until_vnf_delete(vnf_id,
                                constants.VNF_CIRROS_DELETE_TIMEOUT)
     self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE,
                                 evt_constants.PENDING_DELETE, cnt=2)
     self.addCleanup(self.client.delete_vnfd, vnfd_instance['vnfd']['id'])