def test_get_mgmt_network_create(self):
    resource_tag = 'charm-octavia'
    self.patch_object(api_crud, 'neutron_client')
    identity_service = mock.MagicMock()
    nc = mock.MagicMock()
    self.neutron_client.Client.return_value = nc
    network_uuid = '83f1a860-9aed-4c0b-8b72-47195580a0c1'
    nc.create_network.return_value = {'network': {'id': network_uuid}}
    nc.create_subnet.return_value = {'subnets': [{'id': 'fake-subnet-uuid', 'cidr': 'fake-cidr'}]}
    nc.create_router.return_value = {'router': {'id': 'fake-router-uuid'}}
    nc.create_security_group.side_effect = [{'security_group': {'id': self.secgrp_uuid}}, {'security_group': {'id': self.health_secgrp_uuid}}]
    self.patch_object(api_crud, 'is_extension_enabled')
    self.is_extension_enabled.return_value = True
    result = api_crud.get_mgmt_network(identity_service)
    nc.list_networks.assert_called_once_with(tags=resource_tag)
    nc.create_network.assert_called_once_with({'network': {'name': octavia.OCTAVIA_MGMT_NET}})
    nc.list_subnets.assert_called_once_with(network_id=network_uuid, tags=resource_tag)
    nc.list_routers.assert_called_once_with(tags=resource_tag)
    nc.create_router.assert_called_once_with({'router': {'name': 'lb-mgmt', 'distributed': False}})
    nc.list_security_groups.assert_any_call(tags=resource_tag)
    nc.list_security_groups.assert_any_call(tags=(resource_tag + '-health'))
    nc.create_security_group_rule.assert_has_calls(self.security_group_rule_calls)
    self.assertEqual(result, ({'id': network_uuid}, {'id': self.secgrp_uuid}))
def test_get_mgmt_network_create(self):
    resource_tag = 'charm-octavia'
    self.patch_object(api_crud, 'neutron_client')
    identity_service = mock.MagicMock()
    nc = mock.MagicMock()
    self.neutron_client.Client.return_value = nc
    network_uuid = '83f1a860-9aed-4c0b-8b72-47195580a0c1'
    nc.create_network.return_value = {'network': {'id': network_uuid}}
    nc.create_subnet.return_value = {'subnets': [{'id': 'fake-subnet-uuid', 'cidr': 'fake-cidr'}]}
    nc.create_router.return_value = {'router': {'id': 'fake-router-uuid'}}
    nc.create_security_group.side_effect = [{'security_group': {'id': self.secgrp_uuid}}, {'security_group': {'id': self.health_secgrp_uuid}}]
    self.patch_object(api_crud, 'is_extension_enabled')
    self.is_extension_enabled.return_value = True
    result = api_crud.get_mgmt_network(identity_service)
    nc.list_networks.assert_called_once_with(tags=resource_tag)
    nc.create_network.assert_called_once_with({'network': {'name': octavia.OCTAVIA_MGMT_NET}})
    nc.list_subnets.assert_called_once_with(network_id=network_uuid, tags=resource_tag)
    nc.list_routers.assert_called_once_with(tags=resource_tag)
    nc.create_router.assert_called_once_with({'router': {'name': 'lb-mgmt', 'distributed': False}})
    nc.list_security_groups.assert_any_call(tags=resource_tag)
    nc.list_security_groups.assert_any_call(tags=(resource_tag + '-health'))
    nc.create_security_group_rule.assert_has_calls(self.security_group_rule_calls)
    self.assertEqual(result, ({'id': network_uuid}, {'id': self.secgrp_uuid}))