def test_request_to_primitive(self): spec = copy.deepcopy(self.spec) body = profiles.ProfileCreateRequestBody(name='test-profile', spec=spec, metadata={'x': 'y'}) sot = profiles.ProfileCreateRequest(profile=body) self.assertIsInstance(sot.profile, profiles.ProfileCreateRequestBody) self.assertEqual('test-profile', sot.profile.name) self.assertEqual({'x': 'y'}, sot.profile.metadata) # request res = sot.obj_to_primitive() self.assertIn('profile', res['senlin_object.changes']) self.assertEqual('ProfileCreateRequest', res['senlin_object.name']) self.assertEqual('senlin', res['senlin_object.namespace']) self.assertEqual('1.0', res['senlin_object.version']) # request body data = res['senlin_object.data']['profile'] self.assertEqual('ProfileCreateRequestBody', data['senlin_object.name']) self.assertEqual('senlin', data['senlin_object.namespace']) self.assertEqual('1.0', data['senlin_object.version']) self.assertIn('name', data['senlin_object.changes']) self.assertIn('spec', data['senlin_object.changes']) self.assertIn('metadata', data['senlin_object.changes']) # spec pd = data['senlin_object.data'] self.assertEqual(u'test-profile', pd['name']) spec_data = jsonutils.loads(pd['spec']) self.assertEqual(u'os.nova.server', spec_data['type']) self.assertEqual(u'1.0', spec_data['version'])
def test_profile_create2_name_conflict(self, mock_get): cfg.CONF.set_override('name_unique', True, enforce_type=True) mock_get.return_value = mock.Mock() spec = { 'type': 'FakeProfile', 'version': '1.0', 'properties': { 'LIST': ['A', 'B'], 'MAP': { 'KEY1': 11, 'KEY2': 12 }, } } body = vorp.ProfileCreateRequestBody(name='FAKE_NAME', spec=spec) req = vorp.ProfileCreateRequest(profile=body) ex = self.assertRaises(rpc.ExpectedException, self.eng.profile_create2, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.BadRequest, ex.exc_info[0]) self.assertEqual( "The request is malformed: A profile named " "'FAKE_NAME' already exists.", six.text_type(ex.exc_info[1])) mock_get.assert_called_once_with(self.ctx, 'FAKE_NAME')
def test_profile_create_request(self): spec = copy.deepcopy(self.spec) body = profiles.ProfileCreateRequestBody(name='foo', spec=spec, metadata={'x': 'y'}) sot = profiles.ProfileCreateRequest(profile=body) self.assertIsInstance(sot.profile, profiles.ProfileCreateRequestBody)
def test_profile_create_invalid_spec(self, mock_create): self._setup_fakes() mock_create.side_effect = exc.InvalidSpec(message="badbad") body = vorp.ProfileCreateRequestBody(name='foo', spec=self.spec) req = vorp.ProfileCreateRequest(profile=body) ex = self.assertRaises(rpc.ExpectedException, self.svc.profile_create, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.InvalidSpec, ex.exc_info[0]) self.assertEqual("badbad", six.text_type(ex.exc_info[1]))
def test_profile_create_type_not_found(self, mock_create): self._setup_fakes() spec = copy.deepcopy(self.spec) spec['type'] = 'Bogus' body = vorp.ProfileCreateRequestBody(name='foo', spec=spec) req = vorp.ProfileCreateRequest(profile=body) ex = self.assertRaises(rpc.ExpectedException, self.svc.profile_create, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceNotFound, ex.exc_info[0]) self.assertEqual("The profile_type 'Bogus-1.0' could not be " "found.", six.text_type(ex.exc_info[1]))
def test_profile_create_default(self, mock_create): x_profile = mock.Mock() x_profile.to_dict.return_value = {'foo': 'bar'} mock_create.return_value = x_profile self._setup_fakes() body = vorp.ProfileCreateRequestBody(name='p-1', spec=self.spec, metadata={'foo': 'bar'}) req = vorp.ProfileCreateRequest(profile=body) result = self.svc.profile_create(self.ctx, req.obj_to_primitive()) self.assertEqual({'foo': 'bar'}, result)