def test_v6_conf_service_valid(self): n = models.Network('id', None, v6_conf_service='dhcp') self.assertEqual(n.v6_conf_service, 'dhcp') n = models.Network('id', None, v6_conf_service='static') self.assertEqual(n.v6_conf_service, 'static') n = models.Network('id', None, v6_conf_service='ra') self.assertEqual(n.v6_conf_service, 'ra')
def test_network_type_valid(self): n = models.Network('id', None, network_type='external') self.assertEqual(n.network_type, 'external') n = models.Network('id', None, network_type='internal') self.assertEqual(n.network_type, 'internal') n = models.Network('id', None, network_type='isolated') self.assertEqual(n.network_type, 'isolated') n = models.Network('id', None, network_type='management') self.assertEqual(n.network_type, 'management')
def test_network(self): interface = mock.Mock() n = models.Network('id', interface, 'name') self.assertEqual(n.id, 'id') self.assertEqual(n.interface, interface) self.assertEqual(n.name, 'name')
def test_dad_for_external(self): mgr = ip.IPManager() with mock.patch.object(mgr, 'generic_to_host', lambda x: x): mgr.disable_duplicate_address_detection( models.Network('ABC123', models.Interface('eth1'), network_type=models.Network.TYPE_EXTERNAL)) assert self.mock_execute.call_count == 0
def test_dad_for_internal(self): mgr = ip.IPManager() with mock.patch.object(mgr, 'generic_to_host', lambda x: x): mgr.disable_duplicate_address_detection( models.Network('ABC123', models.Interface('eth2'), network_type=models.Network.TYPE_INTERNAL)) assert self.mock_execute.call_count == 1 assert self.mock_execute.call_args_list == [ mock.call(['sysctl', '-w', 'net.ipv6.conf.eth2.accept_dad=0'], 'sudo astara-rootwrap /etc/rootwrap.conf'), ]
def test_sysctl_failure(self): logger = ip.LOG logger.level = logging.DEBUG buff = StringIO() handler = logging.StreamHandler(buff) self.mock_execute.side_effect = RuntimeError mgr = ip.IPManager() with mock.patch.object(mgr, 'generic_to_host', lambda x: x): try: logger.addHandler(handler) mgr.disable_duplicate_address_detection( models.Network( 'ABC123', models.Interface('eth0'), network_type=models.Network.TYPE_MANAGEMENT)) assert 'Failed to disable v6 dad on eth0' in buff.getvalue() finally: logger.removeHandler(handler)
def test_v6_conf_service_invalid(self): with self.assertRaises(ValueError): models.Network('id', None, v6_conf_service='invalid')
def test_network_type_invalid(self): with self.assertRaises(ValueError): models.Network('id', None, network_type='invalid')