def test_network_config_not_list(self):
     nic_data = self.nic_data(None)
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual(
         "The 'network_config' section of 'foo' must be"
         " a list.", errors[0])
 def test_resource_config_not_dict(self):
     nic_data = {'resources': {'foo': {'properties': {'config': None}}}}
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual(
         "The 'config' property of 'foo' must be"
         " a dictionary.", errors[0])
 def test_more_than_one_bond(self):
     nic_data = self.nic_data(
         [{"type": "ovs_bridge", "name": "storage", "members": [{"type": "ovs_bond"}, {"type": "ovs_bond"}]}]
     )
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn("Invalid bonding: There are 2 bonds for bridge storage", errors[0])
 def test_bridge_has_type(self):
     nic_data = self.nic_data([{
         'name': 'storage',
         'members': [],
     }])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn('must have a type', errors[0])
 def test_multiple_interfaces_without_bond(self):
     nic_data = self.nic_data(
         [{"type": "ovs_bridge", "name": "storage", "members": [{"type": "interface"}, {"type": "interface"}]}]
     )
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn(
         "Invalid interface: When not using a bond, there can" " only be 1 interface for bridge storage", errors[0]
     )
 def test_ovs_bridge_has_members(self):
     nic_data = self.nic_data([{
         'name': 'storage',
         'type': 'ovs_bridge',
         'members': None,
     }])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn("must contain a 'members' list", errors[0])
 def test_ovs_bridge_members_dict(self):
     nic_data = self.nic_data([{
         'name': 'storage',
         'type': 'ovs_bridge',
         'members': [None],
     }])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn("must be a dictionary.", errors[0])
 def test_one_bond_no_interfaces(self):
     nic_data = self.nic_data([{
         'type': 'ovs_bridge',
         'name': 'storage',
         'members': [
             {
                 'type': 'ovs_bond'
             },
         ],
     }])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual([], errors)
 def test_one_bond_multiple_interfaces(self):
     nic_data = self.nic_data(
         [
             {
                 "type": "ovs_bridge",
                 "name": "storage",
                 "members": [{"type": "ovs_bond"}, {"type": "interface"}, {"type": "interface"}],
             }
         ]
     )
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual([], errors)
 def test_more_than_one_bond(self):
     nic_data = self.nic_data([{
         'type':
         'ovs_bridge',
         'name':
         'storage',
         'members': [
             {
                 'type': 'ovs_bond'
             },
             {
                 'type': 'ovs_bond'
             },
         ],
     }])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn('Invalid bonding: There are 2 bonds for bridge storage',
                   errors[0])
 def test_multiple_interfaces_without_bond(self):
     nic_data = self.nic_data([{
         'type':
         'ovs_bridge',
         'name':
         'storage',
         'members': [
             {
                 'type': 'interface'
             },
             {
                 'type': 'interface'
             },
         ],
     }])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn(
         'Invalid interface: When not using a bond, there can'
         ' only be 1 interface for bridge storage', errors[0])
 def test_non_dict(self):
     errors = validation.check_nic_configs("controller.yaml", None)
     self.assertEqual(len(errors), 1)
     self.assertEqual("The nic_data parameter must be a dictionary.", errors[0])
 def test_bonds_have_type(self):
     nic_data = self.nic_data([{"type": "ovs_bridge", "name": "storage", "members": [{}]}])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn("must have a type.", errors[0])
 def test_ovs_bridge_members_dict(self):
     nic_data = self.nic_data([{"name": "storage", "type": "ovs_bridge", "members": [None]}])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn("must be a dictionary.", errors[0])
 def test_ovs_bridge_has_members(self):
     nic_data = self.nic_data([{"name": "storage", "type": "ovs_bridge", "members": None}])
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertIn("must contain a 'members' list", errors[0])
 def test_network_config_not_list(self):
     nic_data = self.nic_data(None)
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual("The 'network_config' section of 'foo' must be" " a list.", errors[0])
 def test_resource_os_net_config_not_dict(self):
     nic_data = {"resources": {"foo": {"properties": {"config": {"os_net_config": None}}}}}
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual("The 'os_net_config' section of 'foo' must be" " a dictionary.", errors[0])
 def _test_resource_properties_invalid(self, resource):
     nic_data = {'resources': {'foo': resource}}
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual("The 'foo' resource must contain 'properties'.",
                      errors[0])
 def test_resource_not_dict(self):
     nic_data = {"resources": {"foo": None}}
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual("'foo' is not a valid resource.", errors[0])
 def _test_resources_invalid(self, nic_data):
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual("The nic_data must contain the 'resources' key and it" " must be a dictionary.", errors[0])
 def _test_resources_invalid(self, nic_data):
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual(
         "The nic_data must contain the 'resources' key and it"
         " must be a dictionary.", errors[0])
 def test_non_dict(self):
     errors = validation.check_nic_configs("controller.yaml", None)
     self.assertEqual(len(errors), 1)
     self.assertEqual('The nic_data parameter must be a dictionary.',
                      errors[0])
 def _test_resource_properties_invalid(self, resource):
     nic_data = {"resources": {"foo": resource}}
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual("The 'foo' resource must contain 'properties'.", errors[0])
 def test_resource_not_dict(self):
     nic_data = {'resources': {'foo': None}}
     errors = validation.check_nic_configs("controller.yaml", nic_data)
     self.assertEqual(len(errors), 1)
     self.assertEqual("'foo' is not a valid resource.", errors[0])