Esempio n. 1
0
    def test_fill_obj_extarq_fields_with_dep_id(self, mock_get_devprof,
                                                mock_get_ah, mock_get_obj_dep,
                                                mock_obj_devprof):
        in_db_extarq = self.fake_db_extarqs[0]
        # Since state is not 'Bound', attach_handle_get_by_id is not called.
        in_db_extarq['state'] = 'Initial'
        in_db_extarq['deployable_id'] = '1'
        db_devprof = fake_device_profile.get_db_devprofs()[0]
        obj_devprof = fake_device_profile.get_obj_devprofs()[0]

        mock_get_devprof.return_value = db_devprof
        mock_obj_devprof.return_value = obj_devprof
        mock_get_obj_dep.return_value = \
            fake_deployable.fake_deployable_obj(self.context,
                                                uuid=self.deployable_uuids[0])

        out_db_extarq = objects.ExtARQ._fill_obj_extarq_fields(
            self.context, in_db_extarq)

        self.assertEqual(out_db_extarq['device_profile_name'],
                         db_devprof['name'])
        self.assertEqual(out_db_extarq['attach_handle_type'], '')
        self.assertEqual(out_db_extarq['attach_handle_info'], '')
        devprof_group_id = out_db_extarq['device_profile_group_id']
        self.assertEqual(out_db_extarq['device_profile_group'],
                         obj_devprof['groups'][devprof_group_id])
Esempio n. 2
0
    def setUp(self):
        super(DeviceProfilePolicyTest, self).setUp()

        self.flags(enforce_scope=False, group="oslo_policy")
        self.controller = device_profiles.DeviceProfilesController()
        self.fake_dp_objs = fake_device_profile.get_obj_devprofs()
        self.fake_dps = fake_device_profile.get_api_devprofs()
        # check both legacy and new policies for create APIs
        self.create_authorized_contexts = [
            self.legacy_admin_context,  # legacy: admin
            self.system_admin_context,  # new policy: system_admin
            self.project_admin_context
        ]
        self.create_unauthorized_contexts = list(
            set(self.all_contexts) - set(self.create_authorized_contexts))

        # check both legacy and new policies for delete APIs
        self.delete_authorized_contexts = [
            # legacy: admin_or_owner
            self.legacy_admin_context,
            # NOTE(yumeng) although the legacy rule is admin_or_owner,
            # cyborg does not "actually" support owner check for
            # device profile, so we just uncomment legacy_owner_context here.
            # If later we need support owner policy, we should recheck here.
            # self.legacy_owner_context,
            self.system_admin_context,  # new policy: system_admin
            self.project_admin_context
        ]
        self.delete_unauthorized_contexts = list(
            set(self.all_contexts) - set(self.delete_authorized_contexts))
Esempio n. 3
0
    def test_create(self, mock_obj_extarq, mock_obj_dp):
        dp_list = fake_device_profile.get_obj_devprofs()
        mock_obj_dp.return_value = dp = dp_list[0]
        mock_obj_extarq.side_effect = self.fake_extarqs
        params = {'device_profile_name': dp['name']}
        response = self.post_json(self.ARQ_URL, params, headers=self.headers)
        data = jsonutils.loads(response.__dict__['controller_output'])
        out_arqs = data['arqs']

        self.assertEqual(http_client.CREATED, response.status_int)
        self.assertEqual(len(out_arqs), 3)
        for in_extarq, out_arq in zip(self.fake_extarqs, out_arqs):
            self._validate_arq(in_extarq.arq, out_arq)
        for idx, out_arq in enumerate(out_arqs):
            dp_group_id = idx
            self.assertEqual(dp_group_id, out_arq['device_profile_group_id'])
Esempio n. 4
0
 def test_update(self):
     fake_db_devprofs = fake_device_profile.get_db_devprofs()
     fake_obj_devprofs = fake_device_profile.get_obj_devprofs()
     db_devprof = fake_db_devprofs[0]
     db_devprof['created_at'] = None
     db_devprof['updated_at'] = None
     with mock.patch.object(self.dbapi,
                            'device_profile_get_by_uuid',
                            autospec=True) as mock_dp_get:
         mock_dp_get.return_value = db_devprof
         uuid = fake_db_devprofs[0]['uuid']
         # Start with db_devprofs[0], corr. to fake_obj_devprofs[0]
         obj_devprof = objects.DeviceProfile.get_by_uuid(self.context, uuid)
         # Change contents to fake_obj_devprofs[1] except uuid
         obj_devprof = fake_obj_devprofs[1]
         obj_devprof['uuid'] = uuid
         with mock.patch.object(self.dbapi,
                                'device_profile_update',
                                autospec=True) as mock_dp_update:
             mock_dp_update.return_value = db_devprof
             obj_devprof.save(self.context)
             mock_dp_get.assert_called_once_with(self.context, uuid)
             mock_dp_update.assert_called_once()
Esempio n. 5
0
 def setUp(self):
     super(TestDeviceProfileController, self).setUp()
     self.headers = self.gen_headers(self.context)
     self.fake_dp_objs = fake_device_profile.get_obj_devprofs()
     self.fake_dps = fake_device_profile.get_api_devprofs()