Merge "Remove mox from test_neutron_security_group"
This commit is contained in:
commit
e688406891
|
@ -11,7 +11,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mox
|
||||
import mock
|
||||
|
||||
from neutronclient.common import exceptions as neutron_exc
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
|
@ -86,17 +86,16 @@ resources:
|
|||
|
||||
def setUp(self):
|
||||
super(SecurityGroupTest, self).setUp()
|
||||
self.m.StubOutWithMock(neutronclient.Client, 'create_security_group')
|
||||
self.m.StubOutWithMock(
|
||||
neutronclient.Client, 'create_security_group_rule')
|
||||
self.m.StubOutWithMock(neutronclient.Client, 'show_security_group')
|
||||
self.m.StubOutWithMock(
|
||||
neutronclient.Client, 'delete_security_group_rule')
|
||||
self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group')
|
||||
self.m.StubOutWithMock(neutronclient.Client, 'update_security_group')
|
||||
self.mockclient = mock.Mock(spec=neutronclient.Client)
|
||||
self.patchobject(neutronclient, 'Client', return_value=self.mockclient)
|
||||
|
||||
def lookup(client, lookup_type, name, cmd_resource):
|
||||
return name
|
||||
|
||||
self.patchobject(neutronV20, 'find_resourceid_by_name_or_id',
|
||||
side_effect=lookup)
|
||||
self.patchobject(neutron.NeutronClientPlugin, 'has_extension',
|
||||
return_value=True)
|
||||
self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id')
|
||||
|
||||
def create_stack(self, templ):
|
||||
t = template_format.parse(templ)
|
||||
|
@ -196,24 +195,7 @@ resources:
|
|||
|
||||
# create script
|
||||
sg_name = utils.PhysName('test_stack', 'the_sg')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'security_group',
|
||||
'wwww',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('wwww')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'security_group',
|
||||
'xxxx',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('xxxx')
|
||||
neutronclient.Client.create_security_group({
|
||||
'security_group': {
|
||||
'name': sg_name,
|
||||
'description': 'HTTP and SSH access'
|
||||
}
|
||||
}).AndReturn({
|
||||
self.mockclient.create_security_group.return_value = {
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': sg_name,
|
||||
|
@ -243,20 +225,10 @@ resources:
|
|||
}],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
})
|
||||
|
||||
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'
|
||||
}
|
||||
}).AndReturn({
|
||||
|
||||
self.mockclient.create_security_group_rule.side_effect = [
|
||||
{
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': None,
|
||||
|
@ -268,19 +240,8 @@ resources:
|
|||
'security_group_id': 'aaaa',
|
||||
'id': 'bbbb'
|
||||
}
|
||||
})
|
||||
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'
|
||||
}
|
||||
}).AndReturn({
|
||||
},
|
||||
{
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': None,
|
||||
|
@ -292,19 +253,8 @@ resources:
|
|||
'security_group_id': 'aaaa',
|
||||
'id': 'cccc'
|
||||
}
|
||||
})
|
||||
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'
|
||||
}
|
||||
}).AndReturn({
|
||||
},
|
||||
{
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': 'wwww',
|
||||
|
@ -316,8 +266,89 @@ resources:
|
|||
'security_group_id': 'aaaa',
|
||||
'id': 'dddd'
|
||||
}
|
||||
})
|
||||
neutronclient.Client.show_security_group('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'
|
||||
}
|
||||
},
|
||||
{
|
||||
'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'
|
||||
}
|
||||
},
|
||||
{
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': 'aaaa',
|
||||
'remote_ip_prefix': None,
|
||||
'port_range_min': None,
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': None,
|
||||
'protocol': None,
|
||||
'security_group_id': 'aaaa',
|
||||
'id': 'gggg'
|
||||
}
|
||||
},
|
||||
{
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': None,
|
||||
'remote_ip_prefix': None,
|
||||
'port_range_min': None,
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': None,
|
||||
'protocol': None,
|
||||
'security_group_id': 'aaaa',
|
||||
'id': 'hhhh'
|
||||
}
|
||||
},
|
||||
{
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': None,
|
||||
'remote_ip_prefix': None,
|
||||
'port_range_min': None,
|
||||
'ethertype': 'IPv6',
|
||||
'port_range_max': None,
|
||||
'protocol': None,
|
||||
'security_group_id': 'aaaa',
|
||||
'id': 'iiii'
|
||||
}
|
||||
},
|
||||
{
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': None,
|
||||
'remote_ip_prefix': '10.0.0.10/24',
|
||||
'port_range_min': '22',
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': '22',
|
||||
'protocol': 'tcp',
|
||||
'security_group_id': 'aaaa',
|
||||
'id': 'jjjj'
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
self.mockclient.show_security_group.side_effect = [
|
||||
{
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': sg_name,
|
||||
|
@ -347,110 +378,9 @@ resources:
|
|||
}],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
})
|
||||
neutronclient.Client.delete_security_group_rule('aaaa-1').AndReturn(
|
||||
None)
|
||||
neutronclient.Client.delete_security_group_rule('aaaa-2').AndReturn(
|
||||
None)
|
||||
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'
|
||||
}
|
||||
})
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': 'aaaa',
|
||||
'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': 'aaaa',
|
||||
'remote_ip_prefix': None,
|
||||
'port_range_min': None,
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': None,
|
||||
'protocol': None,
|
||||
'security_group_id': 'aaaa',
|
||||
'id': 'gggg'
|
||||
}
|
||||
})
|
||||
|
||||
# update script
|
||||
neutronclient.Client.update_security_group(
|
||||
'aaaa',
|
||||
{'security_group': {
|
||||
'description': 'SSH access for private network',
|
||||
'name': 'myrules'}}
|
||||
).AndReturn({
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': 'myrules',
|
||||
'description': 'SSH access for private network',
|
||||
'security_group_rules': [],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
})
|
||||
|
||||
neutronclient.Client.show_security_group('aaaa').AndReturn(
|
||||
show_created)
|
||||
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)
|
||||
neutronclient.Client.delete_security_group_rule('gggg').AndReturn(None)
|
||||
|
||||
neutronclient.Client.show_security_group('aaaa').AndReturn({
|
||||
},
|
||||
show_created,
|
||||
{
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': 'sc1',
|
||||
|
@ -458,83 +388,25 @@ resources:
|
|||
'security_group_rules': [],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
})
|
||||
},
|
||||
show_created,
|
||||
]
|
||||
self.mockclient.delete_security_group_rule.return_value = None
|
||||
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'ethertype': 'IPv4',
|
||||
'security_group_id': 'aaaa',
|
||||
# update script
|
||||
self.mockclient.update_security_group.return_value = {
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': 'myrules',
|
||||
'description': 'SSH access for private network',
|
||||
'security_group_rules': [],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
}).AndReturn({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': None,
|
||||
'remote_ip_prefix': None,
|
||||
'port_range_min': None,
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': None,
|
||||
'protocol': None,
|
||||
'security_group_id': 'aaaa',
|
||||
'id': 'hhhh'
|
||||
}
|
||||
})
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'ethertype': 'IPv6',
|
||||
'security_group_id': 'aaaa',
|
||||
}
|
||||
}).AndReturn({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': None,
|
||||
'remote_ip_prefix': None,
|
||||
'port_range_min': None,
|
||||
'ethertype': 'IPv6',
|
||||
'port_range_max': None,
|
||||
'protocol': None,
|
||||
'security_group_id': 'aaaa',
|
||||
'id': 'iiii'
|
||||
}
|
||||
})
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': None,
|
||||
'remote_ip_prefix': '10.0.0.10/24',
|
||||
'port_range_min': '22',
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': '22',
|
||||
'protocol': 'tcp',
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}).AndReturn({
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': None,
|
||||
'remote_ip_prefix': '10.0.0.10/24',
|
||||
'port_range_min': '22',
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': '22',
|
||||
'protocol': 'tcp',
|
||||
'security_group_id': 'aaaa',
|
||||
'id': 'jjjj'
|
||||
}
|
||||
})
|
||||
|
||||
# delete script
|
||||
neutronclient.Client.show_security_group('aaaa').AndReturn(
|
||||
show_created)
|
||||
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)
|
||||
neutronclient.Client.delete_security_group_rule('gggg').AndReturn(None)
|
||||
neutronclient.Client.delete_security_group('aaaa').AndReturn(None)
|
||||
self.mockclient.delete_security_group.return_value = None
|
||||
|
||||
self.m.ReplayAll()
|
||||
stack = self.create_stack(self.test_template)
|
||||
|
||||
sg = stack['the_sg']
|
||||
|
@ -545,39 +417,15 @@ resources:
|
|||
stack.update(updated_stack)
|
||||
|
||||
stack.delete()
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_security_group_exception(self):
|
||||
# create script
|
||||
sg_name = utils.PhysName('test_stack', 'the_sg')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'security_group',
|
||||
'wwww',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('wwww')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'security_group',
|
||||
'xxxx',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('xxxx')
|
||||
neutronclient.Client.create_security_group({
|
||||
self.mockclient.create_security_group.assert_called_once_with({
|
||||
'security_group': {
|
||||
'name': sg_name,
|
||||
'description': 'HTTP and SSH access'
|
||||
}
|
||||
}).AndReturn({
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': sg_name,
|
||||
'description': 'HTTP and SSH access',
|
||||
'security_group_rules': [],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
})
|
||||
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
self.mockclient.create_security_group_rule.assert_has_calls([
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': None,
|
||||
|
@ -588,9 +436,8 @@ resources:
|
|||
'protocol': 'tcp',
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}).AndRaise(
|
||||
neutron_exc.Conflict())
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': None,
|
||||
|
@ -601,9 +448,8 @@ resources:
|
|||
'protocol': 'tcp',
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}).AndRaise(
|
||||
neutron_exc.Conflict())
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': 'wwww',
|
||||
|
@ -614,18 +460,8 @@ resources:
|
|||
'protocol': 'tcp',
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}).AndRaise(
|
||||
neutron_exc.Conflict())
|
||||
neutronclient.Client.show_security_group('aaaa').AndReturn({
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': sg_name,
|
||||
'description': 'HTTP and SSH access',
|
||||
'security_group_rules': [],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
})
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': None,
|
||||
|
@ -636,9 +472,8 @@ resources:
|
|||
'protocol': 'tcp',
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}).AndRaise(
|
||||
neutron_exc.Conflict())
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': 'xxxx',
|
||||
|
@ -649,9 +484,8 @@ resources:
|
|||
'protocol': None,
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}).AndRaise(
|
||||
neutron_exc.Conflict())
|
||||
neutronclient.Client.create_security_group_rule({
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': 'aaaa',
|
||||
|
@ -662,11 +496,94 @@ resources:
|
|||
'protocol': None,
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}).AndRaise(
|
||||
neutron_exc.Conflict())
|
||||
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'ethertype': 'IPv4',
|
||||
'security_group_id': 'aaaa',
|
||||
}
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'ethertype': 'IPv6',
|
||||
'security_group_id': 'aaaa',
|
||||
}
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'ingress',
|
||||
'remote_group_id': None,
|
||||
'remote_ip_prefix': '10.0.0.10/24',
|
||||
'port_range_min': '22',
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': '22',
|
||||
'protocol': 'tcp',
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}),
|
||||
])
|
||||
self.mockclient.show_security_group.assert_called_with('aaaa')
|
||||
self.mockclient.delete_security_group_rule.assert_has_calls([
|
||||
mock.call('aaaa-1'),
|
||||
mock.call('aaaa-2'),
|
||||
# update script
|
||||
mock.call('bbbb'),
|
||||
mock.call('cccc'),
|
||||
mock.call('dddd'),
|
||||
mock.call('eeee'),
|
||||
mock.call('ffff'),
|
||||
mock.call('gggg'),
|
||||
# delete script
|
||||
neutronclient.Client.show_security_group('aaaa').AndReturn({
|
||||
mock.call('bbbb'),
|
||||
mock.call('cccc'),
|
||||
mock.call('dddd'),
|
||||
mock.call('eeee'),
|
||||
mock.call('ffff'),
|
||||
mock.call('gggg'),
|
||||
])
|
||||
self.mockclient.update_security_group.assert_called_once_with(
|
||||
'aaaa',
|
||||
{'security_group': {
|
||||
'description': 'SSH access for private network',
|
||||
'name': 'myrules'}}
|
||||
)
|
||||
self.mockclient.delete_security_group.assert_called_once_with('aaaa')
|
||||
|
||||
def test_security_group_exception(self):
|
||||
# create script
|
||||
sg_name = utils.PhysName('test_stack', 'the_sg')
|
||||
self.mockclient.create_security_group.return_value = {
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': sg_name,
|
||||
'description': 'HTTP and SSH access',
|
||||
'security_group_rules': [],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
}
|
||||
self.mockclient.create_security_group_rule.side_effect = [
|
||||
neutron_exc.Conflict,
|
||||
neutron_exc.Conflict,
|
||||
neutron_exc.Conflict,
|
||||
neutron_exc.Conflict,
|
||||
neutron_exc.Conflict,
|
||||
neutron_exc.Conflict,
|
||||
]
|
||||
|
||||
self.mockclient.show_security_group.side_effect = [
|
||||
{
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': sg_name,
|
||||
'description': 'HTTP and SSH access',
|
||||
'security_group_rules': [],
|
||||
'id': 'aaaa'
|
||||
}
|
||||
},
|
||||
# delete script
|
||||
{
|
||||
'security_group': {
|
||||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'name': 'sc1',
|
||||
|
@ -738,26 +655,17 @@ resources:
|
|||
'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
|
||||
'port_range_min': None
|
||||
}],
|
||||
'id': 'aaaa'}})
|
||||
neutronclient.Client.delete_security_group_rule('bbbb').AndRaise(
|
||||
'id': 'aaaa'}
|
||||
},
|
||||
neutron_exc.NeutronClientException(status_code=404),
|
||||
]
|
||||
|
||||
# delete script
|
||||
self.mockclient.delete_security_group_rule.side_effect = (
|
||||
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_rule('gggg').AndRaise(
|
||||
neutron_exc.NeutronClientException(status_code=404))
|
||||
neutronclient.Client.delete_security_group('aaaa').AndRaise(
|
||||
self.mockclient.delete_security_group.side_effect = (
|
||||
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)
|
||||
|
||||
sg = stack['the_sg']
|
||||
|
@ -770,7 +678,96 @@ resources:
|
|||
sg.resource_id = 'aaaa'
|
||||
stack.delete()
|
||||
|
||||
self.m.VerifyAll()
|
||||
self.mockclient.create_security_group.assert_called_once_with({
|
||||
'security_group': {
|
||||
'name': sg_name,
|
||||
'description': 'HTTP and SSH access'
|
||||
}
|
||||
})
|
||||
self.mockclient.create_security_group_rule.assert_has_calls([
|
||||
mock.call({
|
||||
'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'
|
||||
}
|
||||
}),
|
||||
mock.call({
|
||||
'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'
|
||||
}
|
||||
}),
|
||||
mock.call({
|
||||
'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'
|
||||
}
|
||||
}),
|
||||
mock.call({
|
||||
'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'
|
||||
}
|
||||
}),
|
||||
mock.call({
|
||||
'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'
|
||||
}
|
||||
}),
|
||||
mock.call({
|
||||
'security_group_rule': {
|
||||
'direction': 'egress',
|
||||
'remote_group_id': 'aaaa',
|
||||
'remote_ip_prefix': None,
|
||||
'port_range_min': None,
|
||||
'ethertype': 'IPv4',
|
||||
'port_range_max': None,
|
||||
'protocol': None,
|
||||
'security_group_id': 'aaaa'
|
||||
}
|
||||
}),
|
||||
])
|
||||
self.mockclient.show_security_group.assert_called_with('aaaa')
|
||||
self.mockclient.delete_security_group_rule.assert_has_calls([
|
||||
mock.call('bbbb'),
|
||||
mock.call('cccc'),
|
||||
mock.call('dddd'),
|
||||
mock.call('eeee'),
|
||||
mock.call('ffff'),
|
||||
mock.call('gggg'),
|
||||
])
|
||||
self.mockclient.delete_security_group.assert_called_with('aaaa')
|
||||
|
||||
def test_security_group_validate(self):
|
||||
stack = self.create_stack(self.test_template_validate)
|
||||
|
|
Loading…
Reference in New Issue