Merge "Remove mox usage from `aws/test_security_group.py`"
This commit is contained in:
commit
7d878a88c9
|
@ -14,6 +14,7 @@
|
||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
import mock
|
||||||
from neutronclient.common import exceptions as neutron_exc
|
from neutronclient.common import exceptions as neutron_exc
|
||||||
from neutronclient.v2_0 import client as neutronclient
|
from neutronclient.v2_0 import client as neutronclient
|
||||||
|
|
||||||
|
@ -66,16 +67,21 @@ Resources:
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(SecurityGroupTest, self).setUp()
|
super(SecurityGroupTest, self).setUp()
|
||||||
self.m.StubOutWithMock(neutronclient.Client, 'create_security_group')
|
self.m_csg = self.patchobject(neutronclient.Client,
|
||||||
self.m.StubOutWithMock(
|
'create_security_group')
|
||||||
|
self.m_csgr = self.patchobject(
|
||||||
neutronclient.Client, 'create_security_group_rule')
|
neutronclient.Client, 'create_security_group_rule')
|
||||||
self.m.StubOutWithMock(neutronclient.Client, 'show_security_group')
|
self.m_ssg = self.patchobject(neutronclient.Client,
|
||||||
self.m.StubOutWithMock(
|
'show_security_group')
|
||||||
|
self.m_dsgr = self.patchobject(
|
||||||
neutronclient.Client, 'delete_security_group_rule')
|
neutronclient.Client, 'delete_security_group_rule')
|
||||||
self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group')
|
self.m_dsg = self.patchobject(
|
||||||
self.m.StubOutWithMock(neutronclient.Client, 'update_security_group')
|
neutronclient.Client, 'delete_security_group')
|
||||||
|
self.m_usg = self.patchobject(
|
||||||
|
neutronclient.Client, 'update_security_group')
|
||||||
self.patchobject(resource.Resource, 'is_using_neutron',
|
self.patchobject(resource.Resource, 'is_using_neutron',
|
||||||
return_value=True)
|
return_value=True)
|
||||||
|
self.sg_name = utils.PhysName('test_stack', 'the_sg')
|
||||||
|
|
||||||
def mock_no_neutron(self):
|
def mock_no_neutron(self):
|
||||||
self.patchobject(resource.Resource, 'is_using_neutron',
|
self.patchobject(resource.Resource, 'is_using_neutron',
|
||||||
|
@ -100,17 +106,73 @@ Resources:
|
||||||
self.assertEqual(ref_id, rsrc.FnGetRefId())
|
self.assertEqual(ref_id, rsrc.FnGetRefId())
|
||||||
self.assertEqual(metadata, dict(rsrc.metadata_get()))
|
self.assertEqual(metadata, dict(rsrc.metadata_get()))
|
||||||
|
|
||||||
def stubout_neutron_create_security_group(self):
|
def validate_create_security_group_rule_calls(self):
|
||||||
sg_name = utils.PhysName('test_stack', 'the_sg')
|
expected = [
|
||||||
neutronclient.Client.create_security_group({
|
mock.call(
|
||||||
|
{'security_group_rule': {
|
||||||
|
'security_group_id': 'aaaa', 'protocol': 'tcp',
|
||||||
|
'port_range_max': 22, 'direction': 'ingress',
|
||||||
|
'remote_group_id': None, 'ethertype': 'IPv4',
|
||||||
|
'remote_ip_prefix': '0.0.0.0/0', 'port_range_min': 22}}
|
||||||
|
),
|
||||||
|
mock.call(
|
||||||
|
{'security_group_rule': {
|
||||||
|
'security_group_id': 'aaaa', 'protocol': 'tcp',
|
||||||
|
'port_range_max': 80, 'direction': 'ingress',
|
||||||
|
'remote_group_id': None, 'ethertype': 'IPv4',
|
||||||
|
'remote_ip_prefix': '0.0.0.0/0', 'port_range_min': 80}}
|
||||||
|
),
|
||||||
|
mock.call(
|
||||||
|
{'security_group_rule': {
|
||||||
|
'security_group_id': 'aaaa', 'protocol': 'tcp',
|
||||||
|
'port_range_max': None, 'direction': 'ingress',
|
||||||
|
'remote_group_id': 'wwww', 'ethertype': 'IPv4',
|
||||||
|
'remote_ip_prefix': None, 'port_range_min': None}}
|
||||||
|
),
|
||||||
|
mock.call(
|
||||||
|
{'security_group_rule': {
|
||||||
|
'security_group_id': 'aaaa', 'protocol': 'tcp',
|
||||||
|
'port_range_max': 22, 'direction': 'egress',
|
||||||
|
'remote_group_id': None, 'ethertype': 'IPv4',
|
||||||
|
'remote_ip_prefix': '10.0.1.0/24', 'port_range_min': 22}}
|
||||||
|
),
|
||||||
|
mock.call(
|
||||||
|
{'security_group_rule': {
|
||||||
|
'security_group_id': 'aaaa', 'protocol': None,
|
||||||
|
'port_range_max': None, 'direction': 'egress',
|
||||||
|
'remote_group_id': 'xxxx', 'ethertype': 'IPv4',
|
||||||
|
'remote_ip_prefix': None, 'port_range_min': None}})
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assertEqual(expected, self.m_csgr.call_args_list)
|
||||||
|
|
||||||
|
def validate_delete_security_group_rule(self):
|
||||||
|
self.assertEqual(
|
||||||
|
[mock.call('aaaa-1'),
|
||||||
|
mock.call('aaaa-2'),
|
||||||
|
mock.call('bbbb'),
|
||||||
|
mock.call('cccc'),
|
||||||
|
mock.call('dddd'),
|
||||||
|
mock.call('eeee'),
|
||||||
|
mock.call('ffff'),
|
||||||
|
],
|
||||||
|
self.m_dsgr.call_args_list)
|
||||||
|
|
||||||
|
def validate_stubout_neutron_create_security_group(self):
|
||||||
|
self.m_csg.assert_called_once_with({
|
||||||
'security_group': {
|
'security_group': {
|
||||||
'name': sg_name,
|
'name': self.sg_name,
|
||||||
'description': 'HTTP and SSH access'
|
'description': 'HTTP and SSH access'
|
||||||
}
|
}
|
||||||
}).AndReturn({
|
})
|
||||||
|
self.validate_delete_security_group_rule()
|
||||||
|
self.validate_create_security_group_rule_calls()
|
||||||
|
|
||||||
|
def stubout_neutron_create_security_group(self, mock_csgr=True):
|
||||||
|
self.m_csg.return_value = {
|
||||||
'security_group': {
|
'security_group': {
|
||||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||||
'name': sg_name,
|
'name': self.sg_name,
|
||||||
'description': 'HTTP and SSH access',
|
'description': 'HTTP and SSH access',
|
||||||
'security_group_rules': [{
|
'security_group_rules': [{
|
||||||
"direction": "egress",
|
"direction": "egress",
|
||||||
|
@ -137,136 +199,77 @@ Resources:
|
||||||
}],
|
}],
|
||||||
'id': 'aaaa'
|
'id': 'aaaa'
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
if mock_csgr:
|
||||||
neutronclient.Client.delete_security_group_rule('aaaa-1').AndReturn(
|
self.m_csgr.side_effect = [
|
||||||
None)
|
{
|
||||||
neutronclient.Client.delete_security_group_rule('aaaa-2').AndReturn(
|
'security_group_rule': {
|
||||||
None)
|
'direction': 'ingress',
|
||||||
|
'remote_group_id': None,
|
||||||
neutronclient.Client.create_security_group_rule({
|
'remote_ip_prefix': '0.0.0.0/0',
|
||||||
'security_group_rule': {
|
'port_range_min': 22,
|
||||||
'direction': 'ingress',
|
'ethertype': 'IPv4',
|
||||||
'remote_group_id': None,
|
'port_range_max': 22,
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
'protocol': 'tcp',
|
||||||
'port_range_min': 22,
|
'security_group_id': 'aaaa',
|
||||||
'ethertype': 'IPv4',
|
'id': 'bbbb'
|
||||||
'port_range_max': 22,
|
}},
|
||||||
'protocol': 'tcp',
|
{
|
||||||
'security_group_id': 'aaaa'
|
'security_group_rule': {
|
||||||
}
|
'direction': 'ingress',
|
||||||
}).AndReturn({
|
'remote_group_id': None,
|
||||||
'security_group_rule': {
|
'remote_ip_prefix': '0.0.0.0/0',
|
||||||
'direction': 'ingress',
|
'port_range_min': 80,
|
||||||
'remote_group_id': None,
|
'ethertype': 'IPv4',
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
'port_range_max': 80,
|
||||||
'port_range_min': 22,
|
'protocol': 'tcp',
|
||||||
'ethertype': 'IPv4',
|
'security_group_id': 'aaaa',
|
||||||
'port_range_max': 22,
|
'id': 'cccc'
|
||||||
'protocol': 'tcp',
|
}
|
||||||
'security_group_id': 'aaaa',
|
},
|
||||||
'id': 'bbbb'
|
{
|
||||||
}
|
'security_group_rule': {
|
||||||
})
|
'direction': 'ingress',
|
||||||
neutronclient.Client.create_security_group_rule({
|
'remote_group_id': 'wwww',
|
||||||
'security_group_rule': {
|
'remote_ip_prefix': None,
|
||||||
'direction': 'ingress',
|
'port_range_min': None,
|
||||||
'remote_group_id': None,
|
'ethertype': 'IPv4',
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
'port_range_max': None,
|
||||||
'port_range_min': 80,
|
'protocol': 'tcp',
|
||||||
'ethertype': 'IPv4',
|
'security_group_id': 'aaaa',
|
||||||
'port_range_max': 80,
|
'id': 'dddd'
|
||||||
'protocol': 'tcp',
|
}
|
||||||
'security_group_id': 'aaaa'
|
},
|
||||||
}
|
{
|
||||||
}).AndReturn({
|
'security_group_rule': {
|
||||||
'security_group_rule': {
|
'direction': 'egress',
|
||||||
'direction': 'ingress',
|
'remote_group_id': None,
|
||||||
'remote_group_id': None,
|
'remote_ip_prefix': '10.0.1.0/24',
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
'port_range_min': 22,
|
||||||
'port_range_min': 80,
|
'ethertype': 'IPv4',
|
||||||
'ethertype': 'IPv4',
|
'port_range_max': 22,
|
||||||
'port_range_max': 80,
|
'protocol': 'tcp',
|
||||||
'protocol': 'tcp',
|
'security_group_id': 'aaaa',
|
||||||
'security_group_id': 'aaaa',
|
'id': 'eeee'
|
||||||
'id': 'cccc'
|
}
|
||||||
}
|
},
|
||||||
})
|
{
|
||||||
neutronclient.Client.create_security_group_rule({
|
'security_group_rule': {
|
||||||
'security_group_rule': {
|
'direction': 'egress',
|
||||||
'direction': 'ingress',
|
'remote_group_id': 'xxxx',
|
||||||
'remote_group_id': 'wwww',
|
'remote_ip_prefix': None,
|
||||||
'remote_ip_prefix': None,
|
'port_range_min': None,
|
||||||
'port_range_min': None,
|
'ethertype': 'IPv4',
|
||||||
'ethertype': 'IPv4',
|
'port_range_max': None,
|
||||||
'port_range_max': None,
|
'protocol': None,
|
||||||
'protocol': 'tcp',
|
'security_group_id': 'aaaa',
|
||||||
'security_group_id': 'aaaa'
|
'id': 'ffff'
|
||||||
}
|
}
|
||||||
}).AndReturn({
|
}
|
||||||
'security_group_rule': {
|
]
|
||||||
'direction': 'ingress',
|
|
||||||
'remote_group_id': 'wwww',
|
|
||||||
'remote_ip_prefix': None,
|
|
||||||
'port_range_min': None,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': None,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa',
|
|
||||||
'id': 'dddd'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'egress',
|
|
||||||
'remote_group_id': None,
|
|
||||||
'remote_ip_prefix': '10.0.1.0/24',
|
|
||||||
'port_range_min': 22,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': 22,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).AndReturn({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'egress',
|
|
||||||
'remote_group_id': None,
|
|
||||||
'remote_ip_prefix': '10.0.1.0/24',
|
|
||||||
'port_range_min': 22,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': 22,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa',
|
|
||||||
'id': 'eeee'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'egress',
|
|
||||||
'remote_group_id': 'xxxx',
|
|
||||||
'remote_ip_prefix': None,
|
|
||||||
'port_range_min': None,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': None,
|
|
||||||
'protocol': None,
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).AndReturn({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'egress',
|
|
||||||
'remote_group_id': 'xxxx',
|
|
||||||
'remote_ip_prefix': None,
|
|
||||||
'port_range_min': None,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': None,
|
|
||||||
'protocol': None,
|
|
||||||
'security_group_id': 'aaaa',
|
|
||||||
'id': 'ffff'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
def stubout_neutron_get_security_group(self):
|
def stubout_neutron_get_security_group(self):
|
||||||
neutronclient.Client.show_security_group('aaaa').AndReturn({
|
self.m_ssg.return_value = {
|
||||||
'security_group': {
|
'security_group': {
|
||||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||||
'name': 'sc1',
|
'name': 'sc1',
|
||||||
|
@ -327,25 +330,14 @@ Resources:
|
||||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||||
'port_range_min': None
|
'port_range_min': None
|
||||||
}],
|
}],
|
||||||
'id': 'aaaa'}})
|
'id': 'aaaa'}}
|
||||||
|
|
||||||
def stubout_neutron_delete_security_group_rules(self):
|
|
||||||
self.stubout_neutron_get_security_group()
|
|
||||||
neutronclient.Client.delete_security_group_rule('bbbb').AndReturn(None)
|
|
||||||
neutronclient.Client.delete_security_group_rule('cccc').AndReturn(None)
|
|
||||||
neutronclient.Client.delete_security_group_rule('dddd').AndReturn(None)
|
|
||||||
neutronclient.Client.delete_security_group_rule('eeee').AndReturn(None)
|
|
||||||
neutronclient.Client.delete_security_group_rule('ffff').AndReturn(None)
|
|
||||||
|
|
||||||
def test_security_group_neutron(self):
|
def test_security_group_neutron(self):
|
||||||
# create script
|
# create script
|
||||||
self.stubout_neutron_create_security_group()
|
self.stubout_neutron_create_security_group()
|
||||||
|
|
||||||
# delete script
|
self.stubout_neutron_get_security_group()
|
||||||
self.stubout_neutron_delete_security_group_rules()
|
|
||||||
neutronclient.Client.delete_security_group('aaaa').AndReturn(None)
|
|
||||||
|
|
||||||
self.m.ReplayAll()
|
|
||||||
stack = self.create_stack(self.test_template_neutron)
|
stack = self.create_stack(self.test_template_neutron)
|
||||||
|
|
||||||
sg = stack['the_sg']
|
sg = stack['the_sg']
|
||||||
|
@ -353,95 +345,28 @@ Resources:
|
||||||
self.assertResourceState(sg, 'aaaa')
|
self.assertResourceState(sg, 'aaaa')
|
||||||
|
|
||||||
stack.delete()
|
stack.delete()
|
||||||
self.m.VerifyAll()
|
self.validate_stubout_neutron_create_security_group()
|
||||||
|
self.m_ssg.assert_called_once_with('aaaa')
|
||||||
|
self.m_dsg.assert_called_once_with('aaaa')
|
||||||
|
|
||||||
def test_security_group_neutron_exception(self):
|
def test_security_group_neutron_exception(self):
|
||||||
# create script
|
# create script
|
||||||
sg_name = utils.PhysName('test_stack', 'the_sg')
|
self.m_csg.return_value = {
|
||||||
neutronclient.Client.create_security_group({
|
|
||||||
'security_group': {
|
|
||||||
'name': sg_name,
|
|
||||||
'description': 'HTTP and SSH access'
|
|
||||||
}
|
|
||||||
}).AndReturn({
|
|
||||||
'security_group': {
|
'security_group': {
|
||||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||||
'name': sg_name,
|
'name': self.sg_name,
|
||||||
'description': 'HTTP and SSH access',
|
'description': 'HTTP and SSH access',
|
||||||
'security_group_rules': [],
|
'security_group_rules': [],
|
||||||
'id': 'aaaa'
|
'id': 'aaaa'
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
self.m_csgr.side_effect = neutron_exc.Conflict
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'ingress',
|
|
||||||
'remote_group_id': None,
|
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
|
||||||
'port_range_min': 22,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': 22,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).AndRaise(
|
|
||||||
neutron_exc.Conflict())
|
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'ingress',
|
|
||||||
'remote_group_id': None,
|
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
|
||||||
'port_range_min': 80,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': 80,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).AndRaise(
|
|
||||||
neutron_exc.Conflict())
|
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'ingress',
|
|
||||||
'remote_group_id': 'wwww',
|
|
||||||
'remote_ip_prefix': None,
|
|
||||||
'port_range_min': None,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': None,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).AndRaise(
|
|
||||||
neutron_exc.Conflict())
|
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'egress',
|
|
||||||
'remote_group_id': None,
|
|
||||||
'remote_ip_prefix': '10.0.1.0/24',
|
|
||||||
'port_range_min': 22,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': 22,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).AndRaise(
|
|
||||||
neutron_exc.Conflict())
|
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'egress',
|
|
||||||
'remote_group_id': 'xxxx',
|
|
||||||
'remote_ip_prefix': None,
|
|
||||||
'port_range_min': None,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': None,
|
|
||||||
'protocol': None,
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).AndRaise(
|
|
||||||
neutron_exc.Conflict())
|
|
||||||
|
|
||||||
# delete script
|
# delete script
|
||||||
neutronclient.Client.show_security_group('aaaa').AndReturn({
|
self.m_dsgr.side_effect = neutron_exc.NeutronClientException(
|
||||||
'security_group': {
|
status_code=404)
|
||||||
|
self.m_ssg.side_effect = [
|
||||||
|
{'security_group': {
|
||||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||||
'name': 'sc1',
|
'name': 'sc1',
|
||||||
'description': '',
|
'description': '',
|
||||||
|
@ -501,24 +426,9 @@ Resources:
|
||||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||||
'port_range_min': None
|
'port_range_min': None
|
||||||
}],
|
}],
|
||||||
'id': 'aaaa'}})
|
'id': 'aaaa'}},
|
||||||
neutronclient.Client.delete_security_group_rule('bbbb').AndRaise(
|
neutron_exc.NeutronClientException(status_code=404)]
|
||||||
neutron_exc.NeutronClientException(status_code=404))
|
|
||||||
neutronclient.Client.delete_security_group_rule('cccc').AndRaise(
|
|
||||||
neutron_exc.NeutronClientException(status_code=404))
|
|
||||||
neutronclient.Client.delete_security_group_rule('dddd').AndRaise(
|
|
||||||
neutron_exc.NeutronClientException(status_code=404))
|
|
||||||
neutronclient.Client.delete_security_group_rule('eeee').AndRaise(
|
|
||||||
neutron_exc.NeutronClientException(status_code=404))
|
|
||||||
neutronclient.Client.delete_security_group_rule('ffff').AndRaise(
|
|
||||||
neutron_exc.NeutronClientException(status_code=404))
|
|
||||||
neutronclient.Client.delete_security_group('aaaa').AndRaise(
|
|
||||||
neutron_exc.NeutronClientException(status_code=404))
|
|
||||||
|
|
||||||
neutronclient.Client.show_security_group('aaaa').AndRaise(
|
|
||||||
neutron_exc.NeutronClientException(status_code=404))
|
|
||||||
|
|
||||||
self.m.ReplayAll()
|
|
||||||
stack = self.create_stack(self.test_template_neutron)
|
stack = self.create_stack(self.test_template_neutron)
|
||||||
|
|
||||||
sg = stack['the_sg']
|
sg = stack['the_sg']
|
||||||
|
@ -531,99 +441,66 @@ Resources:
|
||||||
sg.resource_id = 'aaaa'
|
sg.resource_id = 'aaaa'
|
||||||
stack.delete()
|
stack.delete()
|
||||||
|
|
||||||
self.m.VerifyAll()
|
self.m_csg.assert_called_once_with({
|
||||||
|
'security_group': {
|
||||||
|
'name': self.sg_name,
|
||||||
|
'description': 'HTTP and SSH access'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
self.validate_create_security_group_rule_calls()
|
||||||
|
self.assertEqual(
|
||||||
|
[mock.call('aaaa'), mock.call('aaaa')],
|
||||||
|
self.m_ssg.call_args_list)
|
||||||
|
self.assertEqual(
|
||||||
|
[mock.call('bbbb'), mock.call('cccc'), mock.call('dddd'),
|
||||||
|
mock.call('eeee'), mock.call('ffff')], self.m_dsgr.call_args_list)
|
||||||
|
|
||||||
def test_security_group_neutron_update(self):
|
def test_security_group_neutron_update(self):
|
||||||
# create script
|
# create script
|
||||||
self.stubout_neutron_create_security_group()
|
self.stubout_neutron_create_security_group(mock_csgr=False)
|
||||||
|
|
||||||
# update script
|
# update script
|
||||||
# delete old not needed rules
|
# delete old not needed rules
|
||||||
self.stubout_neutron_get_security_group()
|
self.stubout_neutron_get_security_group()
|
||||||
neutronclient.Client.delete_security_group_rule(
|
|
||||||
'bbbb').InAnyOrder().AndReturn(None)
|
|
||||||
neutronclient.Client.delete_security_group_rule(
|
|
||||||
'dddd').InAnyOrder().AndReturn(None)
|
|
||||||
neutronclient.Client.delete_security_group_rule(
|
|
||||||
'eeee').InAnyOrder().AndReturn(None)
|
|
||||||
|
|
||||||
# create missing rules
|
# create missing rules
|
||||||
neutronclient.Client.create_security_group_rule({
|
self.m_csgr.side_effect = [
|
||||||
'security_group_rule': {
|
{
|
||||||
'direction': 'ingress',
|
'security_group_rule': {
|
||||||
'remote_group_id': None,
|
'direction': 'ingress',
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
'remote_group_id': None,
|
||||||
'port_range_min': 443,
|
'remote_ip_prefix': '0.0.0.0/0',
|
||||||
'ethertype': 'IPv4',
|
'port_range_min': 443,
|
||||||
'port_range_max': 443,
|
'ethertype': 'IPv4',
|
||||||
'protocol': 'tcp',
|
'port_range_max': 443,
|
||||||
'security_group_id': 'aaaa'
|
'protocol': 'tcp',
|
||||||
|
'security_group_id': 'aaaa',
|
||||||
|
'id': 'bbbb'}
|
||||||
|
}, {
|
||||||
|
'security_group_rule': {
|
||||||
|
'direction': 'ingress',
|
||||||
|
'remote_group_id': 'zzzz',
|
||||||
|
'remote_ip_prefix': None,
|
||||||
|
'port_range_min': None,
|
||||||
|
'ethertype': 'IPv4',
|
||||||
|
'port_range_max': None,
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'security_group_id': 'aaaa',
|
||||||
|
'id': 'dddd'}
|
||||||
|
}, {
|
||||||
|
'security_group_rule': {
|
||||||
|
'direction': 'egress',
|
||||||
|
'remote_group_id': None,
|
||||||
|
'remote_ip_prefix': '0.0.0.0/0',
|
||||||
|
'port_range_min': 22,
|
||||||
|
'ethertype': 'IPv4',
|
||||||
|
'port_range_max': 22,
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'security_group_id': 'aaaa',
|
||||||
|
'id': 'eeee'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).InAnyOrder().AndReturn({
|
]
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'ingress',
|
|
||||||
'remote_group_id': None,
|
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
|
||||||
'port_range_min': 443,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': 443,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa',
|
|
||||||
'id': 'bbbb'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'ingress',
|
|
||||||
'remote_group_id': 'zzzz',
|
|
||||||
'remote_ip_prefix': None,
|
|
||||||
'port_range_min': None,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': None,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).InAnyOrder().AndReturn({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'ingress',
|
|
||||||
'remote_group_id': 'zzzz',
|
|
||||||
'remote_ip_prefix': None,
|
|
||||||
'port_range_min': None,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': None,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa',
|
|
||||||
'id': 'dddd'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
neutronclient.Client.create_security_group_rule({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'egress',
|
|
||||||
'remote_group_id': None,
|
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
|
||||||
'port_range_min': 22,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': 22,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa'
|
|
||||||
}
|
|
||||||
}).InAnyOrder().AndReturn({
|
|
||||||
'security_group_rule': {
|
|
||||||
'direction': 'egress',
|
|
||||||
'remote_group_id': None,
|
|
||||||
'remote_ip_prefix': '0.0.0.0/0',
|
|
||||||
'port_range_min': 22,
|
|
||||||
'ethertype': 'IPv4',
|
|
||||||
'port_range_max': 22,
|
|
||||||
'protocol': 'tcp',
|
|
||||||
'security_group_id': 'aaaa',
|
|
||||||
'id': 'eeee'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
stack = self.create_stack(self.test_template_neutron)
|
stack = self.create_stack(self.test_template_neutron)
|
||||||
sg = stack['the_sg']
|
sg = stack['the_sg']
|
||||||
self.assertResourceState(sg, 'aaaa')
|
self.assertResourceState(sg, 'aaaa')
|
||||||
|
@ -653,8 +530,11 @@ Resources:
|
||||||
scheduler.TaskRunner(sg.update, after)()
|
scheduler.TaskRunner(sg.update, after)()
|
||||||
|
|
||||||
self.assertEqual((sg.UPDATE, sg.COMPLETE), sg.state)
|
self.assertEqual((sg.UPDATE, sg.COMPLETE), sg.state)
|
||||||
|
self.m_dsgr.assert_has_calls(
|
||||||
self.m.VerifyAll()
|
[mock.call('aaaa-1'), mock.call('aaaa-2'), mock.call('eeee'),
|
||||||
|
mock.call('dddd'), mock.call('bbbb')],
|
||||||
|
any_order=True)
|
||||||
|
self.m_ssg.assert_called_once_with('aaaa')
|
||||||
|
|
||||||
def test_security_group_neutron_update_with_empty_rules(self):
|
def test_security_group_neutron_update_with_empty_rules(self):
|
||||||
# create script
|
# create script
|
||||||
|
@ -663,12 +543,6 @@ Resources:
|
||||||
# update script
|
# update script
|
||||||
# delete old not needed rules
|
# delete old not needed rules
|
||||||
self.stubout_neutron_get_security_group()
|
self.stubout_neutron_get_security_group()
|
||||||
neutronclient.Client.delete_security_group_rule(
|
|
||||||
'eeee').InAnyOrder().AndReturn(None)
|
|
||||||
neutronclient.Client.delete_security_group_rule(
|
|
||||||
'ffff').InAnyOrder().AndReturn(None)
|
|
||||||
|
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
stack = self.create_stack(self.test_template_neutron)
|
stack = self.create_stack(self.test_template_neutron)
|
||||||
sg = stack['the_sg']
|
sg = stack['the_sg']
|
||||||
|
@ -681,5 +555,8 @@ Resources:
|
||||||
scheduler.TaskRunner(sg.update, after)()
|
scheduler.TaskRunner(sg.update, after)()
|
||||||
|
|
||||||
self.assertEqual((sg.UPDATE, sg.COMPLETE), sg.state)
|
self.assertEqual((sg.UPDATE, sg.COMPLETE), sg.state)
|
||||||
|
self.m_ssg.assert_called_once_with('aaaa')
|
||||||
self.m.VerifyAll()
|
self.m_dsgr.assert_has_calls(
|
||||||
|
[mock.call('aaaa-1'), mock.call('aaaa-2'), mock.call('eeee'),
|
||||||
|
mock.call('ffff')],
|
||||||
|
any_order=True)
|
||||||
|
|
Loading…
Reference in New Issue