OpenStack Compute (Nova) Client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_hosts.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from novaclient.v1_1 import hosts
  2. from tests.v1_1 import fakes
  3. from tests import utils
  4. cs = fakes.FakeClient()
  5. class HostsTest(utils.TestCase):
  6. def test_describe_resource(self):
  7. hs = cs.hosts.get('host')
  8. cs.assert_called('GET', '/os-hosts/host')
  9. [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
  10. def test_list_host(self):
  11. hs = cs.hosts.list_all()
  12. cs.assert_called('GET', '/os-hosts')
  13. [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
  14. [self.assertEqual(h.zone, 'nova1') for h in hs]
  15. def test_list_host_with_zone(self):
  16. hs = cs.hosts.list_all('nova')
  17. cs.assert_called('GET', '/os-hosts?zone=nova')
  18. [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
  19. [self.assertEqual(h.zone, 'nova') for h in hs]
  20. def test_update_enable(self):
  21. host = cs.hosts.get('sample_host')[0]
  22. values = {"status": "enabled"}
  23. result = host.update(values)
  24. cs.assert_called('PUT', '/os-hosts/sample_host', values)
  25. self.assertTrue(isinstance(result, hosts.Host))
  26. def test_update_maintenance(self):
  27. host = cs.hosts.get('sample_host')[0]
  28. values = {"maintenance_mode": "enable"}
  29. result = host.update(values)
  30. cs.assert_called('PUT', '/os-hosts/sample_host', values)
  31. self.assertTrue(isinstance(result, hosts.Host))
  32. def test_update_both(self):
  33. host = cs.hosts.get('sample_host')[0]
  34. values = {"status": "enabled",
  35. "maintenance_mode": "enable"}
  36. result = host.update(values)
  37. cs.assert_called('PUT', '/os-hosts/sample_host', values)
  38. self.assertTrue(isinstance(result, hosts.Host))
  39. def test_host_startup(self):
  40. host = cs.hosts.get('sample_host')[0]
  41. result = host.startup()
  42. cs.assert_called(
  43. 'POST', '/os-hosts/sample_host/action', {'startup': None})
  44. def test_host_reboot(self):
  45. host = cs.hosts.get('sample_host')[0]
  46. result = host.reboot()
  47. cs.assert_called(
  48. 'POST', '/os-hosts/sample_host/action', {'reboot': None})
  49. def test_host_shutdown(self):
  50. host = cs.hosts.get('sample_host')[0]
  51. result = host.shutdown()
  52. cs.assert_called(
  53. 'POST', '/os-hosts/sample_host/action', {'shutdown': None})