def test_get_mgmt_network_exists(self):
    resource_tag = 'charm-octavia'
    self.patch_object(api_crud, 'session_from_identity_service')
    self.patch_object(api_crud, 'init_neutron_client')
    identity_service = mock.MagicMock()
    nc = mock.MagicMock()
    self.init_neutron_client.return_value = nc
    network_uuid = '83f1a860-9aed-4c0b-8b72-47195580a0c1'
    nc.list_networks.return_value = {'networks': [{'id': network_uuid}]}
    nc.list_subnets.return_value = {'subnets': [{'id': 'fake-subnet-uuid'}]}
    nc.list_routers.return_value = {'routers': [{'id': 'fake-router-uuid'}]}
    nc.list_security_groups.side_effect = [{'security_groups': [{'id': self.secgrp_uuid}]}, {'security_groups': [{'id': self.health_secgrp_uuid}]}]
    self.patch_object(api_crud.neutronclient.common, 'exceptions', name='neutron_exceptions')
    self.neutron_exceptions.Conflict = FakeNeutronConflictException
    nc.create_security_group_rule.side_effect = FakeNeutronConflictException
    result = api_crud.get_mgmt_network(identity_service)
    self.init_neutron_client.assert_called_once_with(self.session_from_identity_service())
    nc.list_networks.assert_called_once_with(tags=resource_tag)
    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.list_security_groups.assert_has_calls([mock.call(tags=resource_tag), mock.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_exists(self):
    resource_tag = 'charm-octavia'
    self.patch_object(api_crud, 'session_from_identity_service')
    self.patch_object(api_crud, 'init_neutron_client')
    identity_service = mock.MagicMock()
    nc = mock.MagicMock()
    self.init_neutron_client.return_value = nc
    network_uuid = '83f1a860-9aed-4c0b-8b72-47195580a0c1'
    nc.list_networks.return_value = {'networks': [{'id': network_uuid}]}
    nc.list_subnets.return_value = {'subnets': [{'id': 'fake-subnet-uuid'}]}
    nc.list_routers.return_value = {'routers': [{'id': 'fake-router-uuid'}]}
    nc.list_security_groups.side_effect = [{'security_groups': [{'id': self.secgrp_uuid}]}, {'security_groups': [{'id': self.health_secgrp_uuid}]}]
    self.patch_object(api_crud.neutronclient.common, 'exceptions', name='neutron_exceptions')
    self.neutron_exceptions.Conflict = FakeNeutronConflictException
    nc.create_security_group_rule.side_effect = FakeNeutronConflictException
    result = api_crud.get_mgmt_network(identity_service)
    self.init_neutron_client.assert_called_once_with(self.session_from_identity_service())
    nc.list_networks.assert_called_once_with(tags=resource_tag)
    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.list_security_groups.assert_has_calls([mock.call(tags=resource_tag), mock.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}))