Ejemplo n.º 1
0
    def test_get_action_with_events_project_id_none(self, mock_action_get,
                                                    mock_action_events):
        fake_request_id = 'req-%s' % uuids.req1

        mock_action_get.return_value = objects.InstanceAction(
            id=789,
            action='stop',
            instance_uuid=uuids.instance,
            request_id=fake_request_id,
            user_id=None,
            project_id=None,
            start_time=datetime.datetime(2019, 2, 28, 14, 28, 0, 0),
            finish_time=None,
            message='',
            created_at=None,
            updated_at=None,
            deleted_at=None,
            deleted=False)

        mock_action_events.return_value = [
            objects.InstanceActionEvent(
                id=5,
                action_id=789,
                event='compute_stop_instance',
                start_time=datetime.datetime(2019, 2, 28, 14, 28, 0, 0),
                finish_time=datetime.datetime(2019, 2, 28, 14, 30, 0, 0),
                result='Success',
                traceback='',
                created_at=None,
                updated_at=None,
                deleted_at=None,
                deleted=False,
                host='host2')
        ]

        req = self._get_http_req('os-instance-actions/1',
                                 use_admin_context=True)
        res_dict = self.controller.show(req, uuids.instance, fake_request_id)

        # Assert that 'project_id' is null (None) in the response
        self.assertIsNone(res_dict['instanceAction']['project_id'])
        self.assertEqual('host2',
                         res_dict['instanceAction']['events'][0]['host'])
        # Assert that the 'hostId' is based on 'host' and the project ID
        # of the server
        self.assertEqual(
            utils.generate_hostid(
                res_dict['instanceAction']['events'][0]['host'],
                self.instance_project_id),
            res_dict['instanceAction']['events'][0]['hostId'])
Ejemplo n.º 2
0
 def _format_event(self, event_raw, project_id, show_traceback=False,
                   show_host=False, show_hostid=False):
     event = {}
     for key in EVENT_KEYS:
         # By default, non-admins are not allowed to see traceback details.
         if key == 'traceback' and not show_traceback:
             continue
         event[key] = event_raw.get(key)
     # By default, non-admins are not allowed to see host.
     if show_host:
         event['host'] = event_raw['host']
     if show_hostid:
         event['hostId'] = utils.generate_hostid(event_raw['host'],
                                                 project_id)
     return event
Ejemplo n.º 3
0
 def _format_event(self, event_raw, project_id, show_traceback=False,
                   show_host=False, show_hostid=False):
     event = {}
     for key in EVENT_KEYS:
         # By default, non-admins are not allowed to see traceback details.
         if key == 'traceback' and not show_traceback:
             continue
         event[key] = event_raw.get(key)
     # By default, non-admins are not allowed to see host.
     if show_host:
         event['host'] = event_raw['host']
     if show_hostid:
         event['hostId'] = utils.generate_hostid(event_raw['host'],
                                                 project_id)
     return event
Ejemplo n.º 4
0
    def test_get_action_with_events_project_id_none(self, mock_action_get,
                                                    mock_action_events):
        fake_request_id = 'req-%s' % uuids.req1

        mock_action_get.return_value = objects.InstanceAction(
            id=789,
            action='stop',
            instance_uuid=uuids.instance,
            request_id=fake_request_id,
            user_id=None,
            project_id=None,
            start_time=datetime.datetime(2019, 2, 28, 14, 28, 0, 0),
            finish_time=None,
            message='',
            created_at=None,
            updated_at=None,
            deleted_at=None,
            deleted=False)

        mock_action_events.return_value = [
            objects.InstanceActionEvent(
                id=5,
                action_id=789,
                event='compute_stop_instance',
                start_time=datetime.datetime(2019, 2, 28, 14, 28, 0, 0),
                finish_time=datetime.datetime(2019, 2, 28, 14, 30, 0, 0),
                result='Success',
                traceback='',
                created_at=None,
                updated_at=None,
                deleted_at=None,
                deleted=False,
                host='host2')]

        req = self._get_http_req('os-instance-actions/1',
                                 use_admin_context=True)
        res_dict = self.controller.show(req, uuids.instance, fake_request_id)

        # Assert that 'project_id' is null (None) in the response
        self.assertIsNone(res_dict['instanceAction']['project_id'])
        self.assertEqual('host2',
                         res_dict['instanceAction']['events'][0]['host'])
        # Assert that the 'hostId' is based on 'host' and the project ID
        # of the server
        self.assertEqual(utils.generate_hostid(
            res_dict['instanceAction']['events'][0]['host'],
            self.instance_project_id),
            res_dict['instanceAction']['events'][0]['hostId'])
Ejemplo n.º 5
0
 def _get_host_id(instance):
     host = instance.get("host")
     project = str(instance.get("project_id"))
     return utils.generate_hostid(host, project)
Ejemplo n.º 6
0
 def _get_host_id(instance):
     host = instance.get("host")
     project = str(instance.get("project_id"))
     return utils.generate_hostid(host, project)
Ejemplo n.º 7
0
 def test_generate_hostid_with_none_host(self):
     project_id = '9b9e3c847e904b0686e8ffb20e4c6381'
     self.assertEqual('', utils.generate_hostid(None, project_id))
Ejemplo n.º 8
0
 def test_generate_hostid(self):
     host = 'host'
     project_id = '9b9e3c847e904b0686e8ffb20e4c6381'
     hostId = 'fa123c6f74efd4aad95f84096f9e187caa0625925a9e7837b2b46792'
     self.assertEqual(hostId, utils.generate_hostid(host, project_id))