summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/api/openstack/compute/contrib/aggregates.py3
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_aggregates.py33
2 files changed, 24 insertions, 12 deletions
diff --git a/nova/api/openstack/compute/contrib/aggregates.py b/nova/api/openstack/compute/contrib/aggregates.py
index 84b0358a3..b73a50f39 100644
--- a/nova/api/openstack/compute/contrib/aggregates.py
+++ b/nova/api/openstack/compute/contrib/aggregates.py
@@ -167,7 +167,8 @@ class AggregateController(object):
authorize(context)
try:
aggregate = self.api.remove_host_from_aggregate(context, id, host)
- except (exception.AggregateNotFound, exception.AggregateHostNotFound):
+ except (exception.AggregateNotFound, exception.AggregateHostNotFound,
+ exception.ComputeHostNotFound):
LOG.info(_("Cannot remove host %(host)s in aggregate "
"%(id)s") % locals())
raise exc.HTTPNotFound
diff --git a/nova/tests/api/openstack/compute/contrib/test_aggregates.py b/nova/tests/api/openstack/compute/contrib/test_aggregates.py
index c57d6a91b..bb513bf7d 100644
--- a/nova/tests/api/openstack/compute/contrib/test_aggregates.py
+++ b/nova/tests/api/openstack/compute/contrib/test_aggregates.py
@@ -202,7 +202,7 @@ class AggregateTestCase(test.TestCase):
self.assertRaises(exc.HTTPBadRequest, self.controller.update,
self.req, "2", body=test_metadata)
- def test_update_with_bad_host_aggregate(self):
+ def test_update_with_bad_aggregate(self):
test_metadata = {"aggregate": {"name": "test_name"}}
def stub_update_aggregate(context, aggregate, metadata):
@@ -236,7 +236,7 @@ class AggregateTestCase(test.TestCase):
stub_add_host_to_aggregate)
self.assertRaises(exc.HTTPConflict, self.controller.action,
- self.req, "duplicate_aggregate",
+ self.req, "1",
body={"add_host": {"host": "host1"}})
def test_add_host_with_bad_aggregate(self):
@@ -256,12 +256,12 @@ class AggregateTestCase(test.TestCase):
stub_add_host_to_aggregate)
self.assertRaises(exc.HTTPNotFound, self.controller.action,
- self.req, "bogus_aggregate",
- body={"add_host": {"host": "host1"}})
+ self.req, "1",
+ body={"add_host": {"host": "bogus_host"}})
def test_add_host_with_missing_host(self):
self.assertRaises(exc.HTTPBadRequest, self.controller.action,
- self.req, "1", body={"asdf": "asdf"})
+ self.req, "1", body={"add_host": {"asdf": "asdf"}})
def test_remove_host(self):
def stub_remove_host_from_aggregate(context, aggregate, host):
@@ -288,7 +288,7 @@ class AggregateTestCase(test.TestCase):
self.req, "bogus_aggregate",
body={"remove_host": {"host": "host1"}})
- def test_remove_host_with_bad_host(self):
+ def test_remove_host_with_host_not_in_aggregate(self):
def stub_remove_host_from_aggregate(context, aggregate, host):
raise exception.AggregateHostNotFound(aggregate_id=aggregate,
host=host)
@@ -297,16 +297,27 @@ class AggregateTestCase(test.TestCase):
stub_remove_host_from_aggregate)
self.assertRaises(exc.HTTPNotFound, self.controller.action,
- self.req, "bogus_aggregate",
+ self.req, "1",
body={"remove_host": {"host": "host1"}})
+ def test_remove_host_with_bad_host(self):
+ def stub_remove_host_from_aggregate(context, aggregate, host):
+ raise exception.ComputeHostNotFound(host=host)
+ self.stubs.Set(self.controller.api,
+ "remove_host_from_aggregate",
+ stub_remove_host_from_aggregate)
+
+ self.assertRaises(exc.HTTPNotFound, self.controller.action,
+ self.req, "1", body={"remove_host": {"host": "bogushost"}})
+
def test_remove_host_with_missing_host(self):
self.assertRaises(exc.HTTPBadRequest, self.controller.action,
self.req, "1", body={"asdf": "asdf"})
def test_remove_host_with_extra_param(self):
self.assertRaises(exc.HTTPBadRequest, self.controller.action,
- self.req, "1", body={"asdf": "asdf", "host": "asdf"})
+ self.req, "1", body={"remove_host": {"asdf": "asdf",
+ "host": "asdf"}})
def test_set_metadata(self):
body = {"set_metadata": {"metadata": {"foo": "bar"}}}
@@ -325,7 +336,7 @@ class AggregateTestCase(test.TestCase):
self.assertEqual(AGGREGATE, result["aggregate"])
- def test_set_metadata_with_bad_host_aggregate(self):
+ def test_set_metadata_with_bad_aggregate(self):
body = {"set_metadata": {"metadata": {"foo": "bar"}}}
def stub_update_aggregate(context, aggregate, metadata):
@@ -340,12 +351,12 @@ class AggregateTestCase(test.TestCase):
def test_set_metadata_with_missing_metadata(self):
body = {"asdf": {"foo": "bar"}}
self.assertRaises(exc.HTTPBadRequest, self.controller.action,
- self.req, "bad_aggregate", body=body)
+ self.req, "1", body=body)
def test_set_metadata_with_extra_params(self):
body = {"metadata": {"foo": "bar"}, "asdf": {"foo": "bar"}}
self.assertRaises(exc.HTTPBadRequest, self.controller.action,
- self.req, "bad_aggregate", body=body)
+ self.req, "1", body=body)
def test_delete_aggregate(self):
def stub_delete_aggregate(context, aggregate):