Merge "Remove mox from test_neutron_provider_net.py"
This commit is contained in:
commit
71a961bcd5
@ -12,8 +12,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from neutronclient.common import exceptions as qe
|
from neutronclient.common import exceptions as qe
|
||||||
from neutronclient.v2_0 import client as neutronclient
|
from neutronclient.v2_0 import client as neutronclient
|
||||||
|
|
||||||
@ -66,33 +66,14 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(NeutronProviderNetTest, self).setUp()
|
super(NeutronProviderNetTest, self).setUp()
|
||||||
self.m.StubOutWithMock(neutronclient.Client, 'create_network')
|
self.mockclient = mock.Mock(spec=neutronclient.Client)
|
||||||
self.m.StubOutWithMock(neutronclient.Client, 'show_network')
|
self.patchobject(neutronclient, 'Client', return_value=self.mockclient)
|
||||||
self.m.StubOutWithMock(neutronclient.Client, 'delete_network')
|
|
||||||
self.m.StubOutWithMock(neutronclient.Client, 'update_network')
|
|
||||||
self.patchobject(neutron.NeutronClientPlugin, 'has_extension',
|
self.patchobject(neutron.NeutronClientPlugin, 'has_extension',
|
||||||
return_value=True)
|
return_value=True)
|
||||||
|
|
||||||
def create_provider_net(self):
|
def create_provider_net(self):
|
||||||
# Create script
|
# Create script
|
||||||
neutronclient.Client.create_network({
|
self.mockclient.create_network.return_value = stpnb
|
||||||
'network': {
|
|
||||||
'name': u'the_provider_network',
|
|
||||||
'admin_state_up': True,
|
|
||||||
'provider:network_type': 'vlan',
|
|
||||||
'provider:physical_network': 'physnet_1',
|
|
||||||
'provider:segmentation_id': '101',
|
|
||||||
'router:external': False,
|
|
||||||
'shared': True}
|
|
||||||
}).AndReturn(stpnb)
|
|
||||||
|
|
||||||
neutronclient.Client.show_network(
|
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
|
|
||||||
).AndReturn(stpnb)
|
|
||||||
|
|
||||||
neutronclient.Client.show_network(
|
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
|
|
||||||
).AndReturn(stpna)
|
|
||||||
|
|
||||||
t = template_format.parse(provider_network_template)
|
t = template_format.parse(provider_network_template)
|
||||||
self.stack = utils.parse_stack(t)
|
self.stack = utils.parse_stack(t)
|
||||||
@ -105,29 +86,17 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
|||||||
|
|
||||||
def test_create_provider_net(self):
|
def test_create_provider_net(self):
|
||||||
rsrc = self.create_provider_net()
|
rsrc = self.create_provider_net()
|
||||||
|
self.mockclient.show_network.side_effect = [
|
||||||
neutronclient.Client.show_network(
|
stpnb,
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
|
stpna,
|
||||||
).AndRaise(qe.NetworkNotFoundClient(status_code=404))
|
qe.NetworkNotFoundClient(status_code=404),
|
||||||
|
stpna,
|
||||||
# Delete script
|
qe.NetworkNotFoundClient(status_code=404),
|
||||||
neutronclient.Client.delete_network(
|
]
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
|
self.mockclient.delete_network.side_effect = [
|
||||||
).AndReturn(None)
|
None,
|
||||||
|
qe.NetworkNotFoundClient(status_code=404),
|
||||||
neutronclient.Client.show_network(
|
]
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
|
|
||||||
).AndReturn(stpna)
|
|
||||||
|
|
||||||
neutronclient.Client.show_network(
|
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
|
|
||||||
).AndRaise(qe.NetworkNotFoundClient(status_code=404))
|
|
||||||
|
|
||||||
neutronclient.Client.delete_network(
|
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
|
|
||||||
).AndRaise(qe.NetworkNotFoundClient(status_code=404))
|
|
||||||
|
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
rsrc.validate()
|
rsrc.validate()
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
@ -146,28 +115,29 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
|||||||
rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE, 'to delete again')
|
rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE, 'to delete again')
|
||||||
scheduler.TaskRunner(rsrc.delete)()
|
scheduler.TaskRunner(rsrc.delete)()
|
||||||
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
|
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
|
||||||
self.m.VerifyAll()
|
|
||||||
|
self.mockclient.create_network.assert_called_once_with({
|
||||||
|
'network': {
|
||||||
|
'name': u'the_provider_network',
|
||||||
|
'admin_state_up': True,
|
||||||
|
'provider:network_type': 'vlan',
|
||||||
|
'provider:physical_network': 'physnet_1',
|
||||||
|
'provider:segmentation_id': '101',
|
||||||
|
'router:external': False,
|
||||||
|
'shared': True
|
||||||
|
}
|
||||||
|
})
|
||||||
|
self.mockclient.show_network.assert_called_with(
|
||||||
|
'fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||||
|
self.assertEqual(5, self.mockclient.show_network.call_count)
|
||||||
|
self.mockclient.delete_network.assert_called_with(
|
||||||
|
'fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||||
|
self.assertEqual(2, self.mockclient.delete_network.call_count)
|
||||||
|
|
||||||
def test_update_provider_net(self):
|
def test_update_provider_net(self):
|
||||||
rsrc = self.create_provider_net()
|
rsrc = self.create_provider_net()
|
||||||
|
self.mockclient.show_network.side_effect = [stpnb, stpna]
|
||||||
neutronclient.Client.update_network(
|
self.mockclient.update_network.return_value = None
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
|
||||||
{'network': {
|
|
||||||
'provider:network_type': 'vlan',
|
|
||||||
'provider:physical_network': 'physnet_1',
|
|
||||||
'provider:segmentation_id': '102',
|
|
||||||
'port_security_enabled': False,
|
|
||||||
'router:external': True
|
|
||||||
}}).AndReturn(None)
|
|
||||||
|
|
||||||
neutronclient.Client.update_network(
|
|
||||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
|
||||||
{'network': {
|
|
||||||
'name': utils.PhysName(rsrc.stack.name, 'provider_net')
|
|
||||||
}}).AndReturn(None)
|
|
||||||
|
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
rsrc.validate()
|
rsrc.validate()
|
||||||
|
|
||||||
@ -190,11 +160,44 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
|||||||
{'name': None}))
|
{'name': None}))
|
||||||
# no prop_diff
|
# no prop_diff
|
||||||
self.assertIsNone(rsrc.handle_update(update_snippet, {}, {}))
|
self.assertIsNone(rsrc.handle_update(update_snippet, {}, {}))
|
||||||
self.m.VerifyAll()
|
|
||||||
|
self.mockclient.create_network.assert_called_once_with({
|
||||||
|
'network': {
|
||||||
|
'name': u'the_provider_network',
|
||||||
|
'admin_state_up': True,
|
||||||
|
'provider:network_type': 'vlan',
|
||||||
|
'provider:physical_network': 'physnet_1',
|
||||||
|
'provider:segmentation_id': '101',
|
||||||
|
'router:external': False,
|
||||||
|
'shared': True}
|
||||||
|
})
|
||||||
|
self.mockclient.show_network.assert_called_with(
|
||||||
|
'fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||||
|
self.assertEqual(2, self.mockclient.show_network.call_count)
|
||||||
|
self.mockclient.update_network.assert_has_calls([
|
||||||
|
mock.call('fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||||
|
{
|
||||||
|
'network': {
|
||||||
|
'provider:network_type': 'vlan',
|
||||||
|
'provider:physical_network': 'physnet_1',
|
||||||
|
'provider:segmentation_id': '102',
|
||||||
|
'port_security_enabled': False,
|
||||||
|
'router:external': True
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
mock.call('fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||||
|
{
|
||||||
|
'network': {
|
||||||
|
'name': utils.PhysName(rsrc.stack.name,
|
||||||
|
'provider_net'),
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
self.assertEqual(2, self.mockclient.update_network.call_count)
|
||||||
|
|
||||||
def test_get_live_state(self):
|
def test_get_live_state(self):
|
||||||
rsrc = self.create_provider_net()
|
rsrc = self.create_provider_net()
|
||||||
rsrc.client().show_network = mock.Mock(return_value={
|
self.mockclient.show_network.return_value = {
|
||||||
'network': {
|
'network': {
|
||||||
'status': 'ACTIVE',
|
'status': 'ACTIVE',
|
||||||
'subnets': [],
|
'subnets': [],
|
||||||
@ -210,7 +213,9 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
|||||||
'shared': True,
|
'shared': True,
|
||||||
'provider:network_type': 'flat',
|
'provider:network_type': 'flat',
|
||||||
'id': 'af216806-4462-4c68-bfa4-9580857e71c3',
|
'id': 'af216806-4462-4c68-bfa4-9580857e71c3',
|
||||||
'provider:segmentation_id': None}})
|
'provider:segmentation_id': None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reality = rsrc.get_live_state(rsrc.properties)
|
reality = rsrc.get_live_state(rsrc.properties)
|
||||||
expected = {
|
expected = {
|
||||||
@ -224,3 +229,5 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.assertEqual(expected, reality)
|
self.assertEqual(expected, reality)
|
||||||
|
|
||||||
|
self.mockclient.show_network.assert_called_once()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user