2011-08-10 13:53:58 -05:00
|
|
|
from novaclient.v1_1 import security_groups
|
|
|
|
from tests import utils
|
2011-12-09 14:26:06 -05:00
|
|
|
from tests.v1_1 import fakes
|
2011-08-10 13:53:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
cs = fakes.FakeClient()
|
|
|
|
|
|
|
|
|
|
|
|
class SecurityGroupsTest(utils.TestCase):
|
2012-09-14 11:31:30 +00:00
|
|
|
def _do_test_list_security_groups(self, search_opts, path):
|
|
|
|
sgs = cs.security_groups.list(search_opts=search_opts)
|
|
|
|
cs.assert_called('GET', path)
|
2011-08-13 16:06:50 -07:00
|
|
|
for sg in sgs:
|
|
|
|
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
|
2011-08-10 13:53:58 -05:00
|
|
|
|
2012-09-14 11:31:30 +00:00
|
|
|
def test_list_security_groups_all_tenants_on(self):
|
|
|
|
self._do_test_list_security_groups(
|
|
|
|
None, '/os-security-groups')
|
|
|
|
|
|
|
|
def test_list_security_groups_all_tenants_on(self):
|
|
|
|
self._do_test_list_security_groups(
|
|
|
|
{'all_tenants': 1}, '/os-security-groups?all_tenants=1')
|
|
|
|
|
|
|
|
def test_list_security_groups_all_tenants_off(self):
|
|
|
|
self._do_test_list_security_groups(
|
|
|
|
{'all_tenants': 0}, '/os-security-groups')
|
|
|
|
|
2011-08-10 17:20:21 -05:00
|
|
|
def test_get_security_groups(self):
|
|
|
|
sg = cs.security_groups.get(1)
|
2011-08-12 10:38:10 -05:00
|
|
|
cs.assert_called('GET', '/os-security-groups/1')
|
2011-08-10 17:20:21 -05:00
|
|
|
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
|
|
|
|
|
2011-08-10 13:53:58 -05:00
|
|
|
def test_delete_security_group(self):
|
|
|
|
sg = cs.security_groups.list()[0]
|
|
|
|
sg.delete()
|
2011-08-12 10:38:10 -05:00
|
|
|
cs.assert_called('DELETE', '/os-security-groups/1')
|
2011-08-10 17:20:21 -05:00
|
|
|
cs.security_groups.delete(1)
|
2011-08-12 10:38:10 -05:00
|
|
|
cs.assert_called('DELETE', '/os-security-groups/1')
|
2011-08-10 13:53:58 -05:00
|
|
|
cs.security_groups.delete(sg)
|
2011-08-12 10:38:10 -05:00
|
|
|
cs.assert_called('DELETE', '/os-security-groups/1')
|
2011-08-10 13:53:58 -05:00
|
|
|
|
|
|
|
def test_create_security_group(self):
|
2011-08-13 16:06:50 -07:00
|
|
|
sg = cs.security_groups.create("foo", "foo barr")
|
2011-08-12 10:38:10 -05:00
|
|
|
cs.assert_called('POST', '/os-security-groups')
|
2011-08-10 13:53:58 -05:00
|
|
|
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
|
2012-01-03 17:00:29 +01:00
|
|
|
|
|
|
|
def test_refresh_security_group(self):
|
|
|
|
sg = cs.security_groups.get(1)
|
|
|
|
sg2 = cs.security_groups.get(1)
|
|
|
|
self.assertEqual(sg.name, sg2.name)
|
|
|
|
sg2.name = "should be test"
|
|
|
|
self.assertNotEqual(sg.name, sg2.name)
|
|
|
|
sg2.get()
|
|
|
|
self.assertEqual(sg.name, sg2.name)
|