def test_check_config_valid_invalid_key(self):
     expected_num_keys = len(loader.VALID_CONFIG_KEYS)
     config = {}
     for i in range(expected_num_keys):
         config["invalid_key" + str(i)] = "some_data" + str(i)
     with self.assertRaises(KeyError):
         loader.check_config_valid(config)
 def test_check_config_valid_invalid_key_number(self):
     config_small = {"invalid_key": "some_data"}
     expected_num_keys = len(loader.VALID_CONFIG_KEYS)
     config_large = {}
     for i in range(expected_num_keys + 1):
         config_large["invalid_key" + str(i)] = "some_data" + str(i)
     with self.assertRaises(KeyError):
         loader.check_config_valid(config_small)
         loader.check_config_valid(config_large)
 def test_check_config_valid_invalid_services(self):
     config = self.get_valid_config_dict()
     # invalid value
     config["services"] = -1
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid value V2
     config["services"] = 0
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
    def test_check_config_valid_invalid_subnets(self):
        config = self.get_valid_config_dict()

        config["subnets"] = ["invalid_type"]
        with self.assertRaises(ValueError):
            loader.check_config_valid(config)

        config["subnets"] = [1.0]
        with self.assertRaises(ValueError):
            loader.check_config_valid(config)

        config["subnets"] = [-1]
        with self.assertRaises(ValueError):
            loader.check_config_valid(config)

        config["subnets"] = [0]
        with self.assertRaises(ValueError):
            loader.check_config_valid(config)
 def test_check_config_valid_invalid_topology(self):
     config = self.get_valid_config_dict()
     # invalid number of rows
     config["topology"] = [[1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # not 2D array
     config["topology"] = [1, 1, 1]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid number of columns
     config["topology"] = [[1, 1], [1, 1], [1, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid number of columns V2
     config["topology"] = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid value
     config["topology"] = [[1.0, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid value V2
     config["topology"] = [[1, -1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid value V3
     config["topology"] = [[1, 1, 1, 1], [1, 1, 2, 1], [1, 1, 1, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid value V4
     config["topology"] = [[1, 1, 1, 1], [1, 1, 1, 1], [1, "invalid", 1, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
 def test_check_config_valid_invalid_value_type(self):
     config = {}
     for k in loader.VALID_CONFIG_KEYS.keys():
         config[k] = "some_data"
     with self.assertRaises(TypeError):
         loader.check_config_valid(config)
 def test_check_config_valid_valid_config(self):
     config = self.get_valid_config_dict()
     try:
         loader.check_config_valid(config)
     except Exception:
         self.fail()
 def test_check_config_valid_invalid_sensitive_machines(self):
     config = self.get_valid_config_dict()
     # too few sensitive_machines
     config["sensitive_machines"] = []
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # too many sensitive_machines
     config["sensitive_machines"] = [[0, 0, 1], [1, 0, 1], [2, 0, 1],
                                     [3, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: too short
     config["sensitive_machines"] = [[0, 0], [1, 0, 1], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: too long
     config["sensitive_machines"] = [[0, 0, 0, 0], [1, 0, 1], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: subnet not int
     config["sensitive_machines"] = [["str_a", 0, 0], [1, 0, 1], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: subnet id too small
     config["sensitive_machines"] = [[0, 0, 0], [-1, 0, 1], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: subnet id too large
     config["sensitive_machines"] = [[0, 0, 0], [1, 0, 1], [3, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: machine id not int
     config["sensitive_machines"] = [[0, "str_a", 0], [1, 0, 1], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: machine id too small
     config["sensitive_machines"] = [[0, 0, 0], [1, -1, 1], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: machine id too large
     config["sensitive_machines"] = [[0, 0, 0], [1, 0, 1], [2, 2, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: value not int or float
     config["sensitive_machines"] = [[0, 0, "str_a"], [1, 0, 1], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: value too small
     config["sensitive_machines"] = [[0, 0, 0], [1, 0, 1], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # invalid tuple form: value too small V2
     config["sensitive_machines"] = [[0, 0, 100], [1, 0, -1.0], [2, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # duplicate machine addresses
     config["sensitive_machines"] = [[0, 0, 1], [1, 0, 1], [0, 0, 1]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)
     # duplicate machine addresses V2
     config["sensitive_machines"] = [[0, 0, 1], [1, 0, 1], [0, 0, 5]]
     with self.assertRaises(ValueError):
         loader.check_config_valid(config)