Example #1
0
 def test_destroy_compute_node(self, mock_db_inst, mock_delete,
                               mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     compute_node = utils.create_test_compute_node(
         context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(
         compute_node.as_dict())
     dbapi.destroy_compute_node(self.context, compute_node.uuid)
     mock_delete.assert_called_once_with(
         '/compute_nodes/%s' % compute_node.uuid)
Example #2
0
 def test_get_compute_node_by_uuid(self, mock_db_inst,
                                   mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     compute_node = utils.create_test_compute_node(
         context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(
         compute_node.as_dict())
     res = dbapi.get_compute_node(self.context, compute_node.uuid)
     self.assertEqual(compute_node.uuid, res.uuid)
     self.assertEqual(compute_node.hostname, res.hostname)
Example #3
0
    def test_update_zun_service(self, mock_update, mock_write, mock_read):
        mock_read.side_effect = etcd.EtcdKeyNotFound
        service = utils.create_test_zun_service()
        new_host = 'new-host'

        mock_read.side_effect = lambda *args: FakeEtcdResult(service.as_dict())
        dbapi.update_zun_service(service.host, service.binary,
                                 {'host': new_host})
        self.assertEqual(
            new_host,
            json.loads(mock_update.call_args_list[0][0][0].value)['host'])
Example #4
0
    def test_update_container(self, mock_update, mock_write, mock_read):
        mock_read.side_effect = etcd.EtcdKeyNotFound
        container = utils.create_test_container(context=self.context)
        new_image = 'new-image'

        mock_read.side_effect = lambda *args: FakeEtcdResult(container.as_dict(
        ))
        dbapi.update_container(self.context, container.uuid,
                               {'image': new_image})
        self.assertEqual(
            new_image,
            json.loads(mock_update.call_args_list[0][0][0].value)['image'])
Example #5
0
    def test_update_capsule(self, mock_update, mock_write, mock_read):
        mock_read.side_effect = etcd.EtcdKeyNotFound
        capsule = utils.create_test_capsule(context=self.context)
        new_meta_name = 'new_meta_name'

        mock_read.side_effect = lambda *args: FakeEtcdResult(capsule.as_dict())
        dbapi.update_capsule(self.context, capsule.uuid,
                             {'meta_name': new_meta_name})
        self.assertEqual(
            new_meta_name,
            json.loads(mock_update.call_args_list[0][0][0].value.decode(
                'utf-8'))['meta_name'])
Example #6
0
 def test_update_compute_node(self, mock_update, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     compute_node = utils.create_test_compute_node(context=self.context)
     old_name = compute_node.hostname
     new_name = 'new-name'
     self.assertNotEqual(old_name, new_name)
     mock_read.side_effect = lambda *args: FakeEtcdResult(compute_node.
                                                          as_dict())
     dbapi.update_compute_node(self.context, compute_node.uuid,
                               {'hostname': new_name})
     self.assertEqual(
         new_name,
         json.loads(mock_update.call_args_list[0][0][0].value)['hostname'])
Example #7
0
 def test_update_resource_class(self, mock_update, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     resource_class = utils.create_test_resource_class(context=self.context)
     old_name = resource_class.name
     new_name = 'new-name'
     self.assertNotEqual(old_name, new_name)
     mock_read.side_effect = lambda *args: FakeEtcdResult(resource_class.
                                                          as_dict())
     dbapi.update_resource_class(self.context, resource_class.uuid,
                                 {'name': new_name})
     self.assertEqual(
         new_name,
         json.loads(mock_update.call_args_list[0][0][0].value)['name'])
Example #8
0
    def test_update_volume_mapping(self, mock_update, mock_write, mock_read):
        mock_read.side_effect = etcd.EtcdKeyNotFound
        volume_mapping = utils.create_test_volume_mapping(context=self.context)
        new_conn_info = 'new-conn-info'

        mock_read.side_effect = lambda *args: FakeEtcdResult(volume_mapping.
                                                             as_dict())
        dbapi.update_volume_mapping(self.context, volume_mapping.uuid,
                                    {'container_info': new_conn_info})
        self.assertEqual(
            new_conn_info,
            json.loads(mock_update.call_args_list[0][0][0].value.decode(
                'utf-8'))['container_info'])
Example #9
0
    def test_container_action_event_finish_success(
            self, mock_db_inst, mock_get_event_by_name,
            mock__action_get_by_request_id,
            mock_update, mock_write, mock_read):
        """Finish a container action event."""
        mock_db_inst.return_value = etcdapi.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound
        uuid = uuidutils.generate_uuid()

        action = dbapi.action_start(self.context,
                                    self._create_action_values(uuid))

        event_values = self._create_event_values(uuid)
        event_values['action_uuid'] = action['uuid']

        mock__action_get_by_request_id.return_value = action
        mock_read.side_effect = etcd.EtcdKeyNotFound
        event = dbapi.action_event_start(self.context, event_values)

        event_values = {
            'finish_time': timeutils.utcnow() + timedelta(seconds=5),
            'result': 'Success'
        }

        event_values = self._create_event_values(uuid, extra=event_values)

        mock__action_get_by_request_id.return_value = action
        mock_get_event_by_name.return_value = event
        mock_read.side_effect = lambda *args: FakeEtcdResult(event)
        event = dbapi.action_event_finish(self.context, event_values)

        event['start_time'] = datetime.isoformat(event['start_time'])
        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult([event])
        self._assertActionEventSaved(event, action['uuid'])

        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult([action])
        action = dbapi.action_get_by_request_id(self.context, uuid,
                                                self.context.request_id)
        self.assertNotEqual('Error', action['message'])
Example #10
0
 def test_get_compute_node_by_name(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     node = utils.create_test_compute_node(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(node.as_dict())
     res = dbapi.get_compute_node(self.context, node.hostname)
     self.assertEqual(node.uuid, res.uuid)
Example #11
0
 def test_destroy_capsule_by_uuid(self, mock_delete, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     capsule = utils.create_test_capsule(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(capsule.as_dict())
     dbapi.destroy_capsule(self.context, capsule.uuid)
     mock_delete.assert_called_once_with('/capsules/%s' % capsule.uuid)