Example #1
0
    def test_detail_vlan_api_error(self):
        resource_data = {}
        obj_id = '|'.join(['msa_vlan', 'msa_vlan', 'vlan_table'])
        for key, value in RESOURCE_RETURN_MAPPING['msa_vlan'].iteritems():
            api_return_data = fixture.RESOURCE_DATA_MSA_VLAN[key]
            if isinstance(api_return_data, dict):
                resource_data[key] = Resource(api_return_data, value)
            else:
                resource_data[key] = []
                for resource_row in api_return_data:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='msa_vlan').AndRaise(OSError)

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['all_resource'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_LIST[key]:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='all_resource')\
            .AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(
            reverse(RESOURCE_DETAIL_URL, kwargs={"resource_id": obj_id}))
        self.assertRedirects(res, RESOURCE_INDEX_URL)
Example #2
0
    def test_detail_pod_detail_api_error(self):
        obj_id = '|'.join(
            ['cpu_detail', 'cpu(vim)', 'pod0001', 'pod_detail_table'])

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='cpu_detail',
                              add_params=IsA({})).AndRaise(OSError)

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['cpu_list'].iteritems():
            api_return_data = fixture.RESOURCE_DATA_POD_LIST[key]
            if isinstance(api_return_data, dict):
                resource_data[key] = Resource(api_return_data, value)
            else:
                resource_data[key] = []
                for resource_row in api_return_data:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='cpu_list',
                              add_params=IsA({})).AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(
            reverse(RESOURCE_DETAIL_URL, kwargs={"resource_id": obj_id}))

        obj_id = '|'.join(['cpu_list', 'cpu(vim)', 'pod_list_table'])
        self.assertRedirects(
            res, reverse(RESOURCE_DETAIL_URL, kwargs={"resource_id": obj_id}))
Example #3
0
    def test_detail_resource_error(self):
        obj_id = '|'.join(['appliances',
                           'intersec_sg_ext',
                           'project_base_table'])
        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type=obj_id.split('|')[0],
                              add_params=IsA({})
                              ).AndRaise(OSError)

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['all_resource'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_LIST[key]:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type='all_resource')\
            .AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(reverse(RESOURCE_DETAIL_URL,
                                      kwargs={"resource_id": obj_id}))
        self.assertRedirects(res, RESOURCE_INDEX_URL)
Example #4
0
    def test_update_status_none(self):

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['ext_globalip'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_GLOBALIP[key]:
                    resource_data[key].append(Resource(resource_row, value))

        node_data = []
        for data in fixture.NODE_DATA_LIST:
            node_data.append(Node(data,
                                  NODE_RETURN_MAPPING['all_node']['Virtual']))

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type='ext_globalip')\
            .AndReturn(resource_data)

        nal_api.get_nodes(IsA(http.HttpRequest),
                          IsA('str'),
                          func_type='all_node')\
            .AndReturn(node_data)

        self.mox.ReplayAll()

        obj_id = '|'.join(['ext_globalip',
                           'global_ip',
                           '135'])
        res = self.client.get(reverse(RESOURCE_UPDATE_URL,
                                      kwargs={'resource_id': obj_id,
                                              'update_type': 'change_status'}))
        self.assertNoFormErrors(res)
        self.assertTemplateUsed(res, 'project/resource/update.html')
Example #5
0
    def test_detail_resource_data(self):

        resource_data = {}
        obj_id = '|'.join(['appliances',
                           'intersec_sg_ext',
                           'project_base_table'])
        for key, value in RESOURCE_RETURN_MAPPING['appliances'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_VNF[key]:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type=obj_id.split('|')[0],
                              add_params=IsA({}))\
            .AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(reverse(RESOURCE_DETAIL_URL,
                                      kwargs={"resource_id": obj_id}))
        self.assertNoFormErrors(res)
        self.assertTemplateUsed(res, 'project/resource/index.html')
        self.assertItemsEqual(res.context['table'].data,
                              resource_data['contract_info'])
Example #6
0
    def test_index_api_error(self):

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='all_resource').AndRaise(OSError)

        self.mox.ReplayAll()
        res = self.client.get(RESOURCE_INDEX_URL)
        self.assertTemplateUsed(res, 'admin/resource/index.html')
        self.assertMessageCount(res, error=1)
Example #7
0
    def test_detail_pod_detail_tenant_error(self):
        resource_data = {}
        obj_id = '|'.join(
            ['cpu_detail', 'cpu(vim)', 'pod0001', 'pod_detail_table'])
        for key, value in RESOURCE_RETURN_MAPPING['cpu_detail'].iteritems():
            api_return_data = fixture.RESOURCE_DATA_POD_DETAIL[key]
            if isinstance(api_return_data, dict):
                resource_data[key] = Resource(api_return_data, value)
            else:
                resource_data[key] = []
                for resource_row in api_return_data:
                    resource_data[key].append(Resource(resource_row, value))

        tenant_list = [{
            'id': 'aaa8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameA'
        }, {
            'id': 'bbb8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameB'
        }, {
            'id': 'ccc8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameC'
        }]
        tenant_data = []
        for data in tenant_list:
            tenant_data.append(Tenant(data))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='cpu_detail',
                              add_params=IsA({})).AndReturn(resource_data)

        api.keystone.tenant_list(IsA(http.HttpRequest),
                                 paginate=True).AndRaise(OSError)

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['cpu_list'].iteritems():
            api_return_data = fixture.RESOURCE_DATA_POD_LIST[key]
            if isinstance(api_return_data, dict):
                resource_data[key] = Resource(api_return_data, value)
            else:
                resource_data[key] = []
                for resource_row in api_return_data:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='cpu_list',
                              add_params=IsA({})).AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(
            reverse(RESOURCE_DETAIL_URL, kwargs={"resource_id": obj_id}))

        obj_id = '|'.join(['cpu_list', 'cpu(vim)', 'pod_list_table'])
        self.assertRedirects(
            res, reverse(RESOURCE_DETAIL_URL, kwargs={"resource_id": obj_id}))
Example #8
0
    def test_index_api_error(self):

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type='all_resource').AndRaise(OSError)

        self.mox.ReplayAll()
        res = self.client.get(RESOURCE_INDEX_URL)

        self.assertTemplateUsed(res, 'project/resource/index.html')
        self.assertItemsEqual(res.context['table'].data, [])
        self.assertMessageCount(res, error=1)
Example #9
0
    def test_index_no_data(self):

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['all_resource'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='all_resource')\
            .AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(RESOURCE_INDEX_URL)
        self.assertNoFormErrors(res)
        self.assertTemplateUsed(res, 'admin/resource/index.html')
        self.assertItemsEqual(res.context['table'].data, [])
Example #10
0
 def delete(self, request, obj_id):
     func_type = obj_id.split('|')[0]
     resource_key = obj_id.split('|')[1]
     resource_id = obj_id.split('|')[2]
     try:
         tenant_id = request.user.project_id
         resource = nal_api.get_resources(request,
                                          tenant_id,
                                          func_type=func_type)
         for contract_data in resource['contract_info']:
             if str(contract_data.id) == resource_id:
                 global_ip = contract_data.resource
                 break
         LOG.info('Deleting resource "%s".' % global_ip)
         params = {
             'function_type': 'globalip_return',
             'global_ip': global_ip
         }
         nal_api.update_resource(request, params)
     except Exception:
         detail_table = RESOURCE_SCREEN_TRANSITION[func_type]
         set_args = '|'.join([func_type, resource_key, detail_table])
         redirect = reverse(constants.RESOURCE_DETAIL_URL,
                            args=(set_args, ))
         exceptions.handle(request, redirect=redirect)
Example #11
0
    def test_resource_get_storage_detail(self):
        """Verify that get storage_detail
        """
        cli_resources = admin_fixture.RESOURCE_DATA_POD_DETAIL

        client = self.stub_nalclient()
        client.resource = self.mox.CreateMockAnything()
        client.resource.get({'operation_id': '1',
                             'function_type': 'storage_detail'})\
            .AndReturn(cli_resources)
        self.mox.ReplayAll()

        api_resources = nal_api.get_resources(self.request,
                                              func_type='storage_detail',
                                              add_params={})

        return_map = RESOURCE_RETURN_MAPPING['storage_detail']
        for key, value in return_map['total_info'].iteritems():
            self.assertEqual(getattr(api_resources['total_info'], key),
                             cli_resources['total_info'].get(value, ''))
        for key, value in return_map['contract_info'].iteritems():
            for (api_resource, cli_resource) in \
                    zip(api_resources['contract_info'],
                        cli_resources['contract_info']):
                self.assertEqual(getattr(api_resource, key),
                                 cli_resource.get(value, ''))
Example #12
0
    def get_data(self):
        resources = []
        try:
            func_type = self.kwargs['func_type']
            resource_key = self.kwargs['resource_key']

            resource_info = self.get_resource_info(func_type, resource_key)
            tenant_id = self.request.user.project_id
            resource_api = nal_api.get_resources(self.request,
                                                 tenant_id,
                                                 func_type=func_type,
                                                 add_params=resource_info)
            resources = resource_api.get('contract_info', [])
        except Exception:
            msg = _('Unable to retrieve resource for each kind.')
            exceptions.handle(self.request,
                              msg,
                              redirect=self.get_redirect_url())

        func_type = self.kwargs['func_type']
        task_status_name = RESOURCE_TASK_STATUS_MAPPING[func_type]
        resource_data = []
        for resource in resources:
            setattr(resource, 'func_type', func_type)
            resource.status_name = task_status_name[str(resource.task_status)]
            resource_data.append(resource)
        return resource_data
Example #13
0
    def test_detail_vlan_tenant_error(self):
        resource_data = {}
        obj_id = '|'.join(['msa_vlan', 'msa_vlan', 'vlan_table'])
        for key, value in RESOURCE_RETURN_MAPPING['msa_vlan'].iteritems():
            api_return_data = fixture.RESOURCE_DATA_MSA_VLAN[key]
            if isinstance(api_return_data, dict):
                resource_data[key] = Resource(api_return_data, value)
            else:
                resource_data[key] = []
                for resource_row in api_return_data:
                    resource_data[key].append(Resource(resource_row, value))

        tenant_list = [{
            'id': 'aaa8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameA'
        }, {
            'id': 'bbb8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameB'
        }, {
            'id': 'ccc8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameC'
        }]
        tenant_data = []
        for data in tenant_list:
            tenant_data.append(Tenant(data))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='msa_vlan').AndReturn(resource_data)

        api.keystone.tenant_list(IsA(http.HttpRequest),
                                 paginate=True).AndRaise(OSError)

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['all_resource'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_LIST[key]:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='all_resource')\
            .AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(
            reverse(RESOURCE_DETAIL_URL, kwargs={"resource_id": obj_id}))
        self.assertRedirects(res, RESOURCE_INDEX_URL)
Example #14
0
    def test_update_parameter_error(self):

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['ext_globalip'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_GLOBALIP[key]:
                    resource_data[key].append(Resource(resource_row, value))

        node_data = []
        for data in fixture.NODE_DATA_LIST:
            node_data.append(Node(data,
                                  NODE_RETURN_MAPPING['all_node']['Virtual']))

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type='ext_globalip')\
            .AndReturn(resource_data)

        nal_api.get_nodes(IsA(http.HttpRequest),
                          IsA('str'),
                          func_type='all_node')\
            .AndReturn(node_data)

        nal_api.update_resource(IsA(http.HttpRequest),
                                IsA({}))\
            .AndRaise(exceptions.NotAvailable())

        self.mox.ReplayAll()

        obj_id = '|'.join(['ext_globalip',
                           'global_ip',
                           '133'])
        formData = {'func_type': 'ext_globalip',
                    'resource': '133',
                    'status': '2',
                    'node_id': 'xxxxx-xxxxx-xxxxx-xxxxx-xxxx1',
                    'update_type': 'change_status'}
        res = self.client.post(reverse(RESOURCE_UPDATE_URL,
                                       args=(obj_id, 'change_status')),
                               formData)

        self.assertTemplateUsed(res, 'project/resource/update.html')
Example #15
0
    def test_index_multi_data(self):

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['all_resource'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_LIST[key]:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='all_resource')\
            .AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(RESOURCE_INDEX_URL)
        self.assertNoFormErrors(res)
        self.assertTemplateUsed(res, 'admin/resource/index.html')
        self.assertItemsEqual(res.context['table'].data,
                              resource_data['contract_info'])
Example #16
0
    def test_update_status_success(self):

        resource_data = {}
        for key, value in RESOURCE_RETURN_MAPPING['ext_globalip'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_GLOBALIP[key]:
                    resource_data[key].append(Resource(resource_row, value))

        node_data = []
        for data in fixture.NODE_DATA_LIST:
            node_data.append(Node(data,
                                  NODE_RETURN_MAPPING['all_node']['Virtual']))

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type='ext_globalip')\
            .AndReturn(resource_data)

        nal_api.get_nodes(IsA(http.HttpRequest),
                          IsA('str'),
                          func_type='all_node')\
            .AndReturn(node_data)

        nal_api.update_resource(IsA(http.HttpRequest),
                                IsA({})).AndReturn(True)

        self.mox.ReplayAll()

        obj_id = '|'.join(['ext_globalip',
                           'global_ip',
                           '133'])
        formData = {'func_type': 'ext_globalip',
                    'resource': '133',
                    'status': '2',
                    'node_id': 'xxxxx-xxxxx-xxxxx-xxxxx-xxxx1',
                    'update_type': 'change_status'}
        res = self.client.post(reverse(RESOURCE_UPDATE_URL,
                                       args=(obj_id, 'change_status')),
                               formData)
        self.assertNoFormErrors(res)
        self.assertMessageCount(success=1)
Example #17
0
    def test_detail_pod_detail_data(self):
        resource_data = {}
        obj_id = '|'.join(
            ['cpu_detail', 'cpu(wim)', 'pod0001', 'pod_detail_table'])
        for key, value in RESOURCE_RETURN_MAPPING['cpu_detail'].iteritems():
            api_return_data = fixture.RESOURCE_DATA_POD_DETAIL[key]
            if isinstance(api_return_data, dict):
                resource_data[key] = Resource(api_return_data, value)
            else:
                resource_data[key] = []
                for resource_row in api_return_data:
                    resource_data[key].append(Resource(resource_row, value))

        tenant_list = [{
            'id': 'aaa8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameA'
        }, {
            'id': 'bbb8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameB'
        }, {
            'id': 'ccc8f50f82da4370813e6ea797b1fb87',
            'name': 'network_nameC'
        }]
        tenant_data = []
        for data in tenant_list:
            tenant_data.append(Tenant(data))

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='cpu_detail',
                              add_params=IsA({})).AndReturn(resource_data)

        api.keystone.tenant_list(IsA(http.HttpRequest),
                                 paginate=True).AndReturn([tenant_data, True])

        self.mox.ReplayAll()
        res = self.client.get(
            reverse(RESOURCE_DETAIL_URL, kwargs={"resource_id": obj_id}))
        self.assertNoFormErrors(res)
        self.assertTemplateUsed(res, 'admin/resource/detail.html')
        disp_column = RESOURCE_DETAIL_DISPLAY_COLUMNS['pod_detail']['detail']
        for i, detail in enumerate(disp_column):
            self.assertItemsEqual(res.context['resource'][i][0], detail[0])
Example #18
0
File: views.py Project: openmsa/NO
    def _get_data(self):
        try:
            func_type = self.kwargs['func_type']
            resource_api = nal_api.get_resources(self.request,
                                                 func_type=func_type)
        except Exception:
            msg = _('Unable to retrieve resource for each kind.')
            exceptions.handle(self.request,
                              msg,
                              redirect=self.get_redirect_url())

        return resource_api
Example #19
0
    def test_detail_globalip_no_data(self):

        resource_data = {}
        obj_id = '|'.join(['ext_globalip',
                           'global_ip',
                           'ext_globalip_table'])
        for key, value in RESOURCE_RETURN_MAPPING['ext_globalip'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type=obj_id.split('|')[0])\
            .AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(reverse(RESOURCE_DETAIL_URL,
                                      kwargs={"resource_id": obj_id}))
        self.assertNoFormErrors(res)
        self.assertTemplateUsed(res, 'project/resource/index.html')
        self.assertItemsEqual(res.context['table'].data, [])
Example #20
0
    def test_detail_pod_list_no_contract_info(self):
        resource_data = {}
        obj_id = '|'.join(['cpu_list', 'cpu(vim)', 'pod_list_table'])
        for key, value in RESOURCE_RETURN_MAPPING['cpu_list'].iteritems():
            api_return_data = fixture.RESOURCE_DATA_POD_LIST[key]
            if isinstance(api_return_data, dict):
                resource_data[key] = Resource(api_return_data, value)
            else:
                resource_data[key] = []

        nal_api.get_resources(IsA(http.HttpRequest),
                              func_type='cpu_list',
                              add_params=IsA({})).AndReturn(resource_data)

        self.mox.ReplayAll()
        res = self.client.get(
            reverse(RESOURCE_DETAIL_URL, kwargs={"resource_id": obj_id}))
        self.assertNoFormErrors(res)
        self.assertTemplateUsed(res, 'admin/resource/detail.html')
        disp_column = RESOURCE_DETAIL_DISPLAY_COLUMNS['pod_list']['detail']
        for i, detail in enumerate(disp_column):
            self.assertItemsEqual(res.context['resource'][i][0], detail[0])
Example #21
0
    def test_delete(self):

        resource_data = {}
        disp_id = '|'.join(['ext_globalip',
                            'global_ip',
                            'ext_globalip_table'])
        for key, value in RESOURCE_RETURN_MAPPING['ext_globalip'].iteritems():
            if isinstance(value, dict):
                resource_data[key] = []
                for resource_row in fixture.RESOURCE_DATA_GLOBALIP[key]:
                    resource_data[key].append(Resource(resource_row, value))

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type=disp_id.split('|')[0])\
            .AndReturn(resource_data)

        nal_api.get_resources(IsA(http.HttpRequest),
                              IsA('str'),
                              func_type=disp_id.split('|')[0])\
            .AndReturn(resource_data)

        nal_api.update_resource(IsA(http.HttpRequest),
                                IsA({})).AndReturn(True)

        self.mox.ReplayAll()

        obj_id = '|'.join(['ext_globalip',
                           'global_ip',
                           '135'])
        formData = {'action': 'resource_globalip__delete__%s' % obj_id}

        res = self.client.post(reverse(RESOURCE_DETAIL_URL,
                                       kwargs={"resource_id": disp_id}),
                               formData)

        self.assertRedirectsNoFollow(res,
                                     reverse(RESOURCE_DETAIL_URL,
                                             kwargs={"resource_id": disp_id}))
Example #22
0
File: views.py Project: openmsa/NO
    def _get_data(self):
        try:
            func_type = self.kwargs['func_type']
            resource_key = self.kwargs['resource_key']
            pod_id = self.kwargs['pod_id']

            resource_info = self.get_resource_info(func_type, resource_key)
            resource_info['pod_id'] = pod_id
            resources = nal_api.get_resources(self.request,
                                              func_type=func_type,
                                              add_params=resource_info)
        except Exception:
            msg = _('Unable to retrieve resource for each kind.')
            exceptions.handle(self.request,
                              msg,
                              redirect=self.get_redirect_url())

        return resources
Example #23
0
    def get_data(self):
        resources = []
        try:
            func_type = self.kwargs['func_type']
            tenant_id = self.request.user.project_id
            resource_api = nal_api.get_resources(self.request,
                                                 tenant_id,
                                                 func_type=func_type)
            resources = resource_api.get('contract_info', [])
        except Exception:
            msg = _('Unable to retrieve resource for each kind.')
            exceptions.handle(self.request,
                              msg,
                              redirect=self.get_redirect_url())

        resource_data = []
        for resource in resources:
            setattr(resource, 'func_type', func_type)
            resource_data.append(resource)
        return resource_data
Example #24
0
    def get_data(self):
        resources = []
        try:
            tenant_id = self.request.user.project_id
            resource_api = nal_api.get_resources(self.request,
                                                 tenant_id,
                                                 func_type='all_resource')
            resources = resource_api.get('contract_info', [])
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve resource list.'))

        resource_list = []
        for resource in resources:
            functions = RESOURCE_FUNCTION_TYPE_MAPPING['project']
            func_type = functions[str(resource.contract_kind)]
            resource_name_map = RESOURCE_NAME_MAPPING[func_type]

            if isinstance(resource_name_map, dict)\
                    and resource.apl_type:
                resource_name_map = resource_name_map[str(resource.apl_type)]

            if isinstance(resource_name_map, dict)\
                    and resource.type:
                resource_name_map = resource_name_map[str(resource.type)]

            if isinstance(resource_name_map, dict)\
                    and resource.device_type:
                resource_name_map = \
                    resource_name_map[str(resource.device_type)]

            if isinstance(resource_name_map, dict)\
                    and resource.redundant:
                resource_name_map = resource_name_map[str(resource.redundant)]

            resource_name = RESOURCE_DISPLAY_NAME_MAPPING[resource_name_map]
            setattr(resource, 'func_type', func_type)
            setattr(resource, 'resource_key', resource_name_map)
            setattr(resource, 'resource_name', resource_name)
            resource_list.append(resource)
        return resource_list
Example #25
0
    def test_resource_get_admin_list(self):
        """Verify that get admin list
        """
        cli_resources = admin_fixture.RESOURCE_DATA_LIST

        client = self.stub_nalclient()
        client.resource = self.mox.CreateMockAnything()
        client.resource.get({'operation_id': '1',
                             'function_type': 'all_resource'})\
            .AndReturn(cli_resources)
        self.mox.ReplayAll()

        api_resources = nal_api.get_resources(self.request)

        for info_key, mapping_dict \
                in RESOURCE_RETURN_MAPPING['all_resource'].iteritems():
            for (api_resource, cli_resource) in zip(api_resources[info_key],
                                                    cli_resources[info_key]):
                for key, value in mapping_dict.iteritems():
                    self.assertEqual(getattr(api_resource, key),
                                     cli_resource.get(value, ''))
Example #26
0
    def test_resource_get_appliances(self):
        """Verify that get appliance
        """
        cli_resources = project_fixture.RESOURCE_DATA_VNF

        client = self.stub_nalclient()
        client.resource = self.mox.CreateMockAnything()
        client.resource.get({'operation_id': '1',
                             'IaaS_tenant_id': 'tenant_id_00001',
                             'function_type': 'appliances'})\
            .AndReturn(cli_resources)
        self.mox.ReplayAll()

        api_resources = nal_api.get_resources(self.request, 'tenant_id_00001',
                                              'appliances')

        for info_key, mapping_dict \
                in RESOURCE_RETURN_MAPPING['appliances'].iteritems():
            for (api_resource, cli_resource) in zip(api_resources[info_key],
                                                    cli_resources[info_key]):
                for key, value in mapping_dict.iteritems():
                    self.assertEqual(getattr(api_resource, key),
                                     cli_resource.get(value, ''))
Example #27
0
File: forms.py Project: openmsa/NO
    def __init__(self, request, *args, **kwargs):
        super(UpdateResourceForm, self).__init__(request, *args, **kwargs)

        func_type = kwargs['initial']['resource_id'].split('|')[0]
        resource_id = kwargs['initial']['resource_id'].split('|')[2]
        update_type = kwargs['initial']['update_type']

        tenant_id = self.request.user.project_id
        resource = nal_api.get_resources(self.request,
                                         tenant_id,
                                         func_type=func_type)
        self.fields['resource'].initial = resource_id
        self.fields['func_type'].initial = func_type
        self.fields['update_type'].initial = update_type

        update_detail_info = RESOURCE_UPDATE_COLUMNS_DEF[update_type]
        if update_detail_info['display_type'] == 'input_column':
            for contract_data in resource['contract_info']:
                if str(contract_data.id) == resource_id:
                    detail_data = contract_data
                    self.fields['resource'].initial = contract_data.resource
                    break
            else:
                raise exceptions.NotFound

            for column in update_detail_info['common']:
                input_attrs = {}
                for attr_key, attr_val in column[1]['widget'].items():
                    input_attrs[attr_key] = attr_val

                if column[1]['field'] == 'ChoiceField':
                    self.fields[column[0]] = getattr(
                        forms, column[1]['field'])(
                            label=column[1]['label'],
                            choices=column[1]['choices'],
                            required=column[1]['required'],
                            widget=forms.Select(attrs=input_attrs))
                else:
                    self.fields[column[0]] = getattr(
                        forms, column[1]['field'])(
                            label=column[1]['label'],
                            required=column[1]['required'],
                            widget=forms.TextInput(attrs=input_attrs))

                if hasattr(detail_data, column[0]):
                    self.fields[column[0]].initial = getattr(
                        detail_data, column[0])

            for column in update_detail_info['separate']:
                input_attrs = {}
                for input in column[1]['input_type']:
                    input_attrs['data-' + input] = column[1]['label']

                input_attrs['class'] = 'switched'
                input_attrs['id'] = column[0]

                if column[1]['field'] == 'ChoiceField':
                    self.fields[column[0]] = \
                        getattr(forms, column[1]['field'])(
                            label=column[1]['label'],
                            choices=column[1]['choices'],
                            required=column[1]['required'],
                            widget=forms.Select(attrs=input_attrs))
                else:
                    self.fields[column[0]] = \
                        getattr(forms, column[1]['field'])(
                            label=column[1]['label'],
                            required=column[1]['required'],
                            widget=forms.TextInput(attrs=input_attrs))

                if hasattr(detail_data, column[0]):
                    self.fields[column[0]].initial = getattr(
                        detail_data, column[0])

            if 'node_id' in self.fields:
                nodes = nal_api.get_nodes(self.request,
                                          tenant_id,
                                          func_type='all_node')

                node_choices = []
                for node in nodes:
                    if node.type == '2':
                        node_choices.append((node.node_id, node.name
                                             or node.node_id))

                if node_choices:
                    self.fields['node_id'].choices = node_choices

                if getattr(detail_data, 'status') != '0':
                    self.fields['status'].initial = '2'
                    self.fields['node_id'].initial = getattr(
                        detail_data, 'node_id')
        else:
            pass