Beispiel #1
0
    def test_spawn_node_trigger_deploy_fail2(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)

        mock_get = mock.patch.object(FAKE_CLIENT.node, 'get').start()
        mock_get.return_value = node
        self.addCleanup(mock_get.stop)
        mock_validate = mock.patch.object(FAKE_CLIENT.node, 'validate').start()
        mock_validate.return_value = ironic_utils.get_test_validation()
        self.addCleanup(mock_validate.stop)

        mock_fg_bid = mock.patch.object(flavor_obj, 'get_by_id').start()
        self.addCleanup(mock_fg_bid.stop)
        mock_pvifs = mock.patch.object(self.driver, '_plug_vifs').start()
        self.addCleanup(mock_pvifs.stop)
        mock_sf = mock.patch.object(self.driver, '_start_firewall').start()
        self.addCleanup(mock_sf.stop)
        mock_cleanup_deploy = mock.patch.object(
            self.driver, '_cleanup_deploy').start()
        self.addCleanup(mock_cleanup_deploy.stop)

        with mock.patch.object(FAKE_CLIENT.node, 'set_provision_state') \
                as mock_sps:
            mock_sps.side_effect = ironic_exception.BadRequest
            self.assertRaises(exception.InstanceDeployFailure,
                              self.driver.spawn,
                              self.ctx, instance, None, [], None)

            mock_get.assert_called_once_with(node_uuid)
            mock_validate.assert_called_once_with(node_uuid)
            mock_fg_bid.assert_called_once_with(self.ctx,
                                                instance['instance_type_id'])
            mock_cleanup_deploy.assert_called_once_with(node, instance, None)
Beispiel #2
0
    def test_spawn(
        self, mock_sf, mock_pvifs, mock_adf, mock_wait_active, mock_fg_bid, mock_node, mock_looping, mock_save
    ):
        node_uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
        node = ironic_utils.get_test_node(driver="fake", uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {"ephemeral_gb": 0}

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        mock_node.get_by_instance_uuid.return_value = node
        mock_node.set_provision_state.return_value = mock.MagicMock()
        mock_fg_bid.return_value = fake_flavor

        fake_looping_call = FakeLoopingCall()
        mock_looping.return_value = fake_looping_call

        self.driver.spawn(self.ctx, instance, None, [], None)

        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_fg_bid.assert_called_once_with(self.ctx, instance["instance_type_id"])
        mock_adf.assert_called_once_with(node, instance, None, fake_flavor)
        mock_pvifs.assert_called_once_with(node, instance, None)
        mock_sf.assert_called_once_with(instance, None)
        mock_node.set_provision_state.assert_called_once_with(node_uuid, "active")

        self.assertIsNone(instance["default_ephemeral_device"])
        self.assertFalse(mock_save.called)

        mock_looping.assert_called_once_with(mock_wait_active, FAKE_CLIENT_WRAPPER, instance)
        fake_looping_call.start.assert_called_once_with(interval=CONF.ironic.api_retry_interval)
        fake_looping_call.wait.assert_called_once()
Beispiel #3
0
    def test_spawn(self, mock_sf, mock_pvifs, mock_adf, mock_cli,
                   mock_fg_bid, mock_node, mock_save):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = { 'ephemeral_gb': 0 }

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        mock_node.get_by_instance_uuid.return_value = node
        mock_node.set_provision_state.return_value = mock.MagicMock()
        mock_fg_bid.return_value = fake_flavor

        node.provision_state = ironic_states.ACTIVE
        mock_cli.return_value = FAKE_CLIENT
        self.driver.spawn(self.ctx, instance, None, [], None)

        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_fg_bid.assert_called_once_with(self.ctx,
                                            instance['instance_type_id'])
        mock_adf.assert_called_once_with(node, instance, None, fake_flavor)
        mock_pvifs.assert_called_once_with(node, instance, None)
        mock_sf.assert_called_once_with(instance, None)
        mock_node.set_provision_state.assert_called_once_with(node_uuid, 'active')

        self.assertIsNone(instance['default_ephemeral_device'])
        self.assertFalse(mock_save.called)
Beispiel #4
0
    def test_spawn_node_trigger_deploy_fail2(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)

        mock_get = mock.patch.object(FAKE_CLIENT.node, 'get').start()
        mock_get.return_value = node
        self.addCleanup(mock_get.stop)
        mock_validate = mock.patch.object(FAKE_CLIENT.node, 'validate').start()
        mock_validate.return_value = ironic_utils.get_test_validation()
        self.addCleanup(mock_validate.stop)

        mock_fg_bid = mock.patch.object(flavor_obj, 'get_by_id').start()
        self.addCleanup(mock_fg_bid.stop)
        mock_pvifs = mock.patch.object(self.driver, '_plug_vifs').start()
        self.addCleanup(mock_pvifs.stop)
        mock_sf = mock.patch.object(self.driver, '_start_firewall').start()
        self.addCleanup(mock_sf.stop)
        mock_cleanup_deploy = mock.patch.object(self.driver,
                                                '_cleanup_deploy').start()
        self.addCleanup(mock_cleanup_deploy.stop)

        with mock.patch.object(FAKE_CLIENT.node, 'set_provision_state') \
                as mock_sps:
            mock_sps.side_effect = ironic_exception.HTTPBadRequest
            self.assertRaises(exception.InstanceDeployFailure,
                              self.driver.spawn, self.ctx, instance, None, [],
                              None)

            mock_get.assert_called_once_with(node_uuid)
            mock_validate.assert_called_once_with(node_uuid)
            mock_fg_bid.assert_called_once_with(self.ctx,
                                                instance['instance_type_id'])
            mock_cleanup_deploy.assert_called_once_with(node, instance, None)
Beispiel #5
0
    def test_spawn_node_prepare_for_deploy_fail(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)

        mock_get = mock.patch.object(FAKE_CLIENT.node, 'get').start()
        mock_get.return_value = node
        self.addCleanup(mock_get.stop)
        mock_validate = mock.patch.object(FAKE_CLIENT.node, 'validate').start()
        mock_validate.return_value = ironic_utils.get_test_validation()
        self.addCleanup(mock_validate.stop)

        mock_fg_bid = mock.patch.object(flavor_obj, 'get_by_id').start()
        self.addCleanup(mock_fg_bid.stop)
        mock_pvifs = mock.patch.object(self.driver, '_plug_vifs').start()
        self.addCleanup(mock_pvifs.stop)
        mock_cleanup_deploy = mock.patch.object(self.driver,
                                                '_cleanup_deploy').start()
        self.addCleanup(mock_cleanup_deploy.stop)

        class TestException(Exception):
            pass

        with mock.patch.object(self.driver, '_start_firewall') as mock_sf:
            mock_sf.side_effect = TestException()
            self.assertRaises(TestException, self.driver.spawn, self.ctx,
                              instance, None, [], None)

            mock_get.assert_called_once_with(node_uuid)
            mock_validate.assert_called_once_with(node_uuid)
            mock_fg_bid.assert_called_once_with(self.ctx,
                                                instance['instance_type_id'])
            mock_cleanup_deploy.assert_called_with(node, instance, None)
Beispiel #6
0
    def test_spawn_node_prepare_for_deploy_fail(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)

        mock_get = mock.patch.object(FAKE_CLIENT.node, 'get').start()
        mock_get.return_value = node
        self.addCleanup(mock_get.stop)
        mock_validate = mock.patch.object(FAKE_CLIENT.node, 'validate').start()
        mock_validate.return_value = ironic_utils.get_test_validation()
        self.addCleanup(mock_validate.stop)

        mock_fg_bid = mock.patch.object(flavor_obj, 'get_by_id').start()
        self.addCleanup(mock_fg_bid.stop)
        mock_pvifs = mock.patch.object(self.driver, '_plug_vifs').start()
        self.addCleanup(mock_pvifs.stop)
        mock_cleanup_deploy = mock.patch.object(
            self.driver, '_cleanup_deploy').start()
        self.addCleanup(mock_cleanup_deploy.stop)

        class TestException(Exception):
            pass

        with mock.patch.object(self.driver, '_start_firewall') as mock_sf:
            mock_sf.side_effect = TestException()
            self.assertRaises(TestException, self.driver.spawn,
                              self.ctx, instance, None, [], None)

            mock_get.assert_called_once_with(node_uuid)
            mock_validate.assert_called_once_with(node_uuid)
            mock_fg_bid.assert_called_once_with(self.ctx,
                                                instance['instance_type_id'])
            mock_cleanup_deploy.assert_called_with(node, instance, None)
Beispiel #7
0
    def test_spawn_node_driver_validation_fail(self, mock_flavor, mock_node):
        node_uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
        node = ironic_utils.get_test_node(driver="fake", uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {"ephemeral_gb": 0}

        mock_node.validate.return_value = ironic_utils.get_test_validation(power=False, deploy=False)
        mock_node.get.return_value = node
        mock_flavor.return_value = fake_flavor
        self.assertRaises(exception.ValidationError, self.driver.spawn, self.ctx, instance, None, [], None)
        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_flavor.assert_called_with(mock.ANY, instance["instance_type_id"])
Beispiel #8
0
    def test_spawn_node_driver_validation_fail(self, mock_flavor, mock_node):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {'ephemeral_gb': 0}

        mock_node.validate.return_value = ironic_utils.get_test_validation(
            power=False, deploy=False)
        mock_node.get.return_value = node
        mock_flavor.return_value = fake_flavor
        self.assertRaises(exception.ValidationError, self.driver.spawn,
                          self.ctx, instance, None, [], None)
        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_flavor.assert_called_with(mock.ANY, instance['instance_type_id'])
Beispiel #9
0
    def test_spawn_node_trigger_deploy_fail2(self, mock_cleanup_deploy, mock_pvifs, mock_sf, mock_flavor, mock_node):
        node_uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
        node = ironic_utils.get_test_node(driver="fake", uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {"ephemeral_gb": 0}
        mock_flavor.return_value = fake_flavor

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        mock_node.set_provision_state.side_effect = ironic_exception.BadRequest
        self.assertRaises(ironic_exception.BadRequest, self.driver.spawn, self.ctx, instance, None, [], None)

        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_flavor.assert_called_once_with(self.ctx, instance["instance_type_id"])
        mock_cleanup_deploy.assert_called_once_with(node, instance, None)
Beispiel #10
0
    def test_spawn_node_driver_validation_fail(self, mock_flavor, mock_cli,
                                               mock_node):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = { 'ephemeral_gb': 0 }

        mock_node.validate.return_value = ironic_utils.get_test_validation(
            power=False, deploy=False)
        mock_node.get.return_value = node
        mock_flavor.return_value = fake_flavor
        mock_cli.return_value = FAKE_CLIENT
        self.assertRaises(exception.ValidationError, self.driver.spawn,
                          self.ctx, instance, None, [], None)
        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_flavor.assert_called_once_with(self.ctx,
                                            instance['instance_type_id'])
Beispiel #11
0
    def test_spawn_node_prepare_for_deploy_fail(self, mock_cleanup_deploy, mock_pvifs, mock_sf, mock_flavor, mock_node):
        node_uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
        node = ironic_utils.get_test_node(driver="fake", uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        fake_flavor = {"ephemeral_gb": 0}
        mock_flavor.return_value = fake_flavor

        class TestException(Exception):
            pass

        mock_sf.side_effect = TestException()
        self.assertRaises(TestException, self.driver.spawn, self.ctx, instance, None, [], None)

        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_flavor.assert_called_once_with(self.ctx, instance["instance_type_id"])
        mock_cleanup_deploy.assert_called_with(node, instance, None)
Beispiel #12
0
    def test_spawn(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = 'fake-flavor'

        mock_get = mock.patch.object(FAKE_CLIENT.node, 'get').start()
        mock_get.return_value = node
        self.addCleanup(mock_get.stop)
        mock_fg_bid = mock.patch.object(flavor_obj, 'get_by_id').start()
        mock_fg_bid.return_value = fake_flavor
        self.addCleanup(mock_fg_bid.stop)

        mock_validate = mock.patch.object(FAKE_CLIENT.node, 'validate').start()
        mock_validate.return_value = ironic_utils.get_test_validation()
        self.addCleanup(mock_validate.stop)

        mock_adf = mock.patch.object(self.driver, '_add_driver_fields').start()
        self.addCleanup(mock_adf.stop)
        mock_pvifs = mock.patch.object(self.driver, '_plug_vifs').start()
        self.addCleanup(mock_pvifs.stop)
        mock_sf = mock.patch.object(self.driver, '_start_firewall').start()
        self.addCleanup(mock_pvifs.stop)

        mock_get_node_by_iuuid = mock.patch.object(
            FAKE_CLIENT.node, 'get_by_instance_uuid').start()
        self.addCleanup(mock_get_node_by_iuuid.stop)
        mock_get_node_by_iuuid.return_value = node

        with mock.patch.object(FAKE_CLIENT.node, 'set_provision_state') \
                as mock_sps:
            node.provision_state = ironic_states.ACTIVE
            self.driver.spawn(self.ctx, instance, None, [], None)

            mock_get.assert_called_once_with(node_uuid)
            mock_validate.assert_called_once_with(node_uuid)
            mock_fg_bid.assert_called_once_with(self.ctx,
                                                instance['instance_type_id'])
            mock_adf.assert_called_once_with(node, instance, None, fake_flavor)
            mock_pvifs.assert_called_once_with(node, instance, None)
            mock_sf.assert_called_once_with(instance, None)
            mock_sps.assert_called_once_with(node_uuid, 'active')
Beispiel #13
0
    def test_spawn(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = 'fake-flavor'

        mock_get = mock.patch.object(FAKE_CLIENT.node, 'get').start()
        mock_get.return_value = node
        self.addCleanup(mock_get.stop)
        mock_fg_bid = mock.patch.object(flavor_obj, 'get_by_id').start()
        mock_fg_bid.return_value = fake_flavor
        self.addCleanup(mock_fg_bid.stop)

        mock_validate = mock.patch.object(FAKE_CLIENT.node, 'validate').start()
        mock_validate.return_value = ironic_utils.get_test_validation()
        self.addCleanup(mock_validate.stop)

        mock_adf = mock.patch.object(self.driver, '_add_driver_fields').start()
        self.addCleanup(mock_adf.stop)
        mock_pvifs = mock.patch.object(self.driver, '_plug_vifs').start()
        self.addCleanup(mock_pvifs.stop)
        mock_sf = mock.patch.object(self.driver, '_start_firewall').start()
        self.addCleanup(mock_pvifs.stop)

        mock_get_node_by_iuuid = mock.patch.object(
            FAKE_CLIENT.node, 'get_by_instance_uuid').start()
        self.addCleanup(mock_get_node_by_iuuid.stop)
        mock_get_node_by_iuuid.return_value = node

        with mock.patch.object(FAKE_CLIENT.node, 'set_provision_state') \
                as mock_sps:
            node.provision_state = ironic_states.ACTIVE
            self.driver.spawn(self.ctx, instance, None, [], None)

            mock_get.assert_called_once_with(node_uuid)
            mock_validate.assert_called_once_with(node_uuid)
            mock_fg_bid.assert_called_once_with(self.ctx,
                                                instance['instance_type_id'])
            mock_adf.assert_called_once_with(node, instance, None, fake_flavor)
            mock_pvifs.assert_called_once_with(node, instance, None)
            mock_sf.assert_called_once_with(instance, None)
            mock_sps.assert_called_once_with(node_uuid, 'active')
Beispiel #14
0
    def test_spawn_node_trigger_deploy_fail2(self, mock_cleanup_deploy,
                                             mock_pvifs, mock_sf, mock_flavor,
                                             mock_node):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {'ephemeral_gb': 0}
        mock_flavor.return_value = fake_flavor

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        mock_node.set_provision_state.side_effect = ironic_exception.BadRequest
        self.assertRaises(exception.InstanceDeployFailure, self.driver.spawn,
                          self.ctx, instance, None, [], None)

        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_flavor.assert_called_once_with(self.ctx,
                                            instance['instance_type_id'])
        mock_cleanup_deploy.assert_called_once_with(node, instance, None)
Beispiel #15
0
    def test_spawn_node_trigger_deploy_fail(self, mock_cleanup_deploy,
                                            mock_pvifs, mock_sf,
                                            mock_flavor, mock_node):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {'ephemeral_gb': 0}
        mock_flavor.return_value = fake_flavor

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()

        mock_node.set_provision_state.side_effect = exception.NovaException()
        self.assertRaises(exception.NovaException, self.driver.spawn,
                          self.ctx, instance, None, [], None)

        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_flavor.assert_called_once_with(self.ctx,
                                            instance['instance_type_id'])
        mock_cleanup_deploy.assert_called_once_with(node, instance, None)
Beispiel #16
0
    def test_spawn_destroyed_after_failure(
        self, mock_sf, mock_pvifs, mock_adf, mock_wait_active, mock_destroy, mock_fg_bid, mock_node, mock_looping
    ):
        node_uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
        node = ironic_utils.get_test_node(driver="fake", uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {"ephemeral_gb": 0}

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        mock_node.get_by_instance_uuid.return_value = node
        mock_node.set_provision_state.return_value = mock.MagicMock()
        mock_fg_bid.return_value = fake_flavor

        fake_looping_call = FakeLoopingCall()
        mock_looping.return_value = fake_looping_call

        deploy_exc = exception.InstanceDeployFailure("foo")
        fake_looping_call.wait.side_effect = deploy_exc
        self.assertRaises(exception.InstanceDeployFailure, self.driver.spawn, self.ctx, instance, None, [], None)
        mock_destroy.assert_called_once_with(self.ctx, instance, None)
Beispiel #17
0
    def test_spawn_node_trigger_deploy_fail3(
        self, mock_destroy, mock_pvifs, mock_sf, mock_flavor, mock_node, mock_looping
    ):
        node_uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
        fake_net_info = utils.get_test_network_info()
        node = ironic_utils.get_test_node(driver="fake", uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {"ephemeral_gb": 0}
        mock_flavor.return_value = fake_flavor

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()

        fake_looping_call = FakeLoopingCall()
        mock_looping.return_value = fake_looping_call

        fake_looping_call.wait.side_effect = ironic_exception.BadRequest
        fake_net_info = utils.get_test_network_info()
        self.assertRaises(
            ironic_exception.BadRequest, self.driver.spawn, self.ctx, instance, None, [], None, fake_net_info
        )
        mock_destroy.assert_called_once_with(self.ctx, instance, fake_net_info)
Beispiel #18
0
    def test_spawn_node_prepare_for_deploy_fail(self, mock_cleanup_deploy,
                                                mock_pvifs, mock_sf,
                                                mock_flavor, mock_node):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        fake_flavor = {'ephemeral_gb': 0}
        mock_flavor.return_value = fake_flavor

        class TestException(Exception):
            pass

        mock_sf.side_effect = TestException()
        self.assertRaises(TestException, self.driver.spawn, self.ctx, instance,
                          None, [], None)

        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_flavor.assert_called_once_with(self.ctx,
                                            instance['instance_type_id'])
        mock_cleanup_deploy.assert_called_with(node, instance, None)
Beispiel #19
0
    def test_spawn_destroyed_after_failure(self, mock_sf, mock_pvifs, mock_adf,
                                           mock_wait_active, mock_destroy,
                                           mock_fg_bid, mock_node,
                                           mock_looping):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {'ephemeral_gb': 0}

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        mock_node.get_by_instance_uuid.return_value = node
        mock_node.set_provision_state.return_value = mock.MagicMock()
        mock_fg_bid.return_value = fake_flavor

        fake_looping_call = FakeLoopingCall()
        mock_looping.return_value = fake_looping_call

        deploy_exc = exception.InstanceDeployFailure('foo')
        fake_looping_call.wait.side_effect = deploy_exc
        self.assertRaises(exception.InstanceDeployFailure, self.driver.spawn,
                          self.ctx, instance, None, [], None)
        mock_destroy.assert_called_once_with(self.ctx, instance, None)
Beispiel #20
0
    def test_spawn(self, mock_sf, mock_pvifs, mock_adf, mock_wait_active,
                   mock_fg_bid, mock_node, mock_looping, mock_save):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(driver='fake', uuid=node_uuid)
        instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
        fake_flavor = {'ephemeral_gb': 0}

        mock_node.get.return_value = node
        mock_node.validate.return_value = ironic_utils.get_test_validation()
        mock_node.get_by_instance_uuid.return_value = node
        mock_node.set_provision_state.return_value = mock.MagicMock()
        mock_fg_bid.return_value = fake_flavor

        fake_looping_call = FakeLoopingCall()
        mock_looping.return_value = fake_looping_call

        self.driver.spawn(self.ctx, instance, None, [], None)

        mock_node.get.assert_called_once_with(node_uuid)
        mock_node.validate.assert_called_once_with(node_uuid)
        mock_fg_bid.assert_called_once_with(self.ctx,
                                            instance['instance_type_id'])
        mock_adf.assert_called_once_with(node, instance, None, fake_flavor)
        mock_pvifs.assert_called_once_with(node, instance, None)
        mock_sf.assert_called_once_with(instance, None)
        mock_node.set_provision_state.assert_called_once_with(
            node_uuid, 'active')

        self.assertIsNone(instance['default_ephemeral_device'])
        self.assertFalse(mock_save.called)

        mock_looping.assert_called_once_with(mock_wait_active,
                                             FAKE_CLIENT_WRAPPER, instance)
        fake_looping_call.start.assert_called_once_with(
            interval=CONF.ironic.api_retry_interval)
        fake_looping_call.wait.assert_called_once()