예제 #1
0
 def test_add_root(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s' % chassis.uuid,
                                [{'path': '/description', 'value': 'test',
                                  'op': 'add'}])
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(http_client.OK, response.status_int)
예제 #2
0
 def test_add_root(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s' % chassis.uuid,
                                [{'path': '/description', 'value': 'test',
                                  'op': 'add'}])
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(http_client.OK, response.status_int)
예제 #3
0
    def test_replace_singular(self, mock_utcnow, mock_notify):
        chassis = obj_utils.get_test_chassis(self.context)
        description = 'chassis-new-description'
        test_time = datetime.datetime(2000, 1, 1, 0, 0)

        mock_utcnow.return_value = test_time
        response = self.patch_json('/chassis/%s' % chassis.uuid,
                                   [{
                                       'path': '/description',
                                       'value': description,
                                       'op': 'replace'
                                   }])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(http_client.OK, response.status_code)
        result = self.get_json('/chassis/%s' % chassis.uuid)
        self.assertEqual(description, result['description'])
        return_updated_at = timeutils.parse_isotime(
            result['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at)
        mock_notify.assert_has_calls([
            mock.call(mock.ANY, mock.ANY, 'update',
                      obj_fields.NotificationLevel.INFO,
                      obj_fields.NotificationStatus.START),
            mock.call(mock.ANY, mock.ANY, 'update',
                      obj_fields.NotificationLevel.INFO,
                      obj_fields.NotificationStatus.END)
        ])
예제 #4
0
 def test_remove_uuid(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s' % chassis.uuid,
                                [{'path': '/uuid', 'op': 'remove'}],
                                expect_errors=True)
     self.assertEqual(http_client.BAD_REQUEST, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['error_message'])
예제 #5
0
 def test_remove_uuid(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s' % chassis.uuid,
                                [{'path': '/uuid', 'op': 'remove'}],
                                expect_errors=True)
     self.assertEqual(http_client.BAD_REQUEST, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['error_message'])
예제 #6
0
 def test_add_root_non_existent(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s' % chassis.uuid,
                                [{'path': '/foo', 'value': 'bar',
                                  'op': 'add'}],
                                expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(http_client.BAD_REQUEST, response.status_int)
     self.assertTrue(response.json['error_message'])
예제 #7
0
 def test_add_root_non_existent(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s' % chassis.uuid,
                                [{'path': '/foo', 'value': 'bar',
                                  'op': 'add'}],
                                expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(http_client.BAD_REQUEST, response.status_int)
     self.assertTrue(response.json['error_message'])
예제 #8
0
 def test_patch_nodes_subresource(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s/nodes' % chassis.uuid,
                                [{
                                    'path': '/extra/foo',
                                    'value': 'bar',
                                    'op': 'add'
                                }],
                                expect_errors=True)
     self.assertEqual(http_client.FORBIDDEN, response.status_int)
예제 #9
0
 def test_add_multi(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s' % chassis.uuid,
                                [{'path': '/extra/foo1', 'value': 'bar1',
                                  'op': 'add'},
                                 {'path': '/extra/foo2', 'value': 'bar2',
                                  'op': 'add'}])
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(http_client.OK, response.status_code)
     result = self.get_json('/chassis/%s' % chassis.uuid)
     expected = {"foo1": "bar1", "foo2": "bar2"}
     self.assertEqual(expected, result['extra'])
예제 #10
0
 def test_update_error(self, mock_save, mock_notify):
     mock_save.side_effect = Exception()
     chassis = obj_utils.get_test_chassis(self.context)
     self.patch_json('/chassis/%s' % chassis.uuid, [{'path': '/description',
                     'value': 'new', 'op': 'replace'}],
                     expect_errors=True)
     mock_notify.assert_has_calls([mock.call(mock.ANY, mock.ANY, 'update',
                                   obj_fields.NotificationLevel.INFO,
                                   obj_fields.NotificationStatus.START),
                                   mock.call(mock.ANY, mock.ANY, 'update',
                                   obj_fields.NotificationLevel.ERROR,
                                   obj_fields.NotificationStatus.ERROR)])
예제 #11
0
 def test_add_multi(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s' % chassis.uuid,
                                [{'path': '/extra/foo1', 'value': 'bar1',
                                  'op': 'add'},
                                 {'path': '/extra/foo2', 'value': 'bar2',
                                  'op': 'add'}])
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(http_client.OK, response.status_code)
     result = self.get_json('/chassis/%s' % chassis.uuid)
     expected = {"foo1": "bar1", "foo2": "bar2"}
     self.assertEqual(expected, result['extra'])
예제 #12
0
 def test_update_error(self, mock_save, mock_notify):
     mock_save.side_effect = Exception()
     chassis = obj_utils.get_test_chassis(self.context)
     self.patch_json('/chassis/%s' % chassis.uuid, [{'path': '/description',
                     'value': 'new', 'op': 'replace'}],
                     expect_errors=True)
     mock_notify.assert_has_calls([mock.call(mock.ANY, mock.ANY, 'update',
                                   obj_fields.NotificationLevel.INFO,
                                   obj_fields.NotificationStatus.START),
                                   mock.call(mock.ANY, mock.ANY, 'update',
                                   obj_fields.NotificationLevel.ERROR,
                                   obj_fields.NotificationStatus.ERROR)])
 def test_chassis_notification(self):
     chassis = obj_utils.get_test_chassis(self.context,
                                          extra={'foo': 'boo'},
                                          description='bare01')
     test_level = fields.NotificationLevel.INFO
     test_status = fields.NotificationStatus.SUCCESS
     notif_utils._emit_api_notification(self.context, chassis, 'create',
                                        test_level, test_status)
     init_kwargs = self.chassis_notify_mock.call_args[1]
     payload = init_kwargs['payload']
     event_type = init_kwargs['event_type']
     self.assertEqual('chassis', event_type.object)
     self.assertEqual(chassis.uuid, payload.uuid)
     self.assertEqual({'foo': 'boo'}, payload.extra)
     self.assertEqual('bare01', payload.description)
예제 #14
0
 def test_chassis_notification(self):
     chassis = obj_utils.get_test_chassis(self.context,
                                          extra={'foo': 'boo'},
                                          description='bare01')
     test_level = fields.NotificationLevel.INFO
     test_status = fields.NotificationStatus.SUCCESS
     notif_utils._emit_api_notification(self.context, chassis, 'create',
                                        test_level, test_status)
     init_kwargs = self.chassis_notify_mock.call_args[1]
     payload = init_kwargs['payload']
     event_type = init_kwargs['event_type']
     self.assertEqual('chassis', event_type.object)
     self.assertEqual(chassis.uuid, payload.uuid)
     self.assertEqual({'foo': 'boo'}, payload.extra)
     self.assertEqual('bare01', payload.description)
예제 #15
0
    def test_replace_singular(self, mock_utcnow):
        chassis = obj_utils.get_test_chassis(self.context)
        description = 'chassis-new-description'
        test_time = datetime.datetime(2000, 1, 1, 0, 0)

        mock_utcnow.return_value = test_time
        response = self.patch_json('/chassis/%s' % chassis.uuid,
                                   [{'path': '/description',
                                     'value': description, 'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(http_client.OK, response.status_code)
        result = self.get_json('/chassis/%s' % chassis.uuid)
        self.assertEqual(description, result['description'])
        return_updated_at = timeutils.parse_isotime(
            result['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at)
예제 #16
0
 def test_patch_nodes_subresource(self):
     chassis = obj_utils.get_test_chassis(self.context)
     response = self.patch_json('/chassis/%s/nodes' % chassis.uuid,
                                [{'path': '/extra/foo', 'value': 'bar',
                                  'op': 'add'}], expect_errors=True)
     self.assertEqual(http_client.FORBIDDEN, response.status_int)