Пример #1
0
 def set_configuration(self, configuration: dict):
     try:
         self.__configuration = MagicCastleConfiguration.get_from_dict(
             configuration)
         self.__hostname = self.__configuration.get_hostname()
     except ValidationError:
         raise InvalidUsageException(
             "The magic castle configuration could not be parsed.")
def test_update_main_tf_json_file():
    modified_config = MagicCastleConfiguration.get_from_dict({
        "cluster_name":
        "missingnodes",
        "domain":
        "sub.example.com",
        "image":
        "CentOS-7-x64-2019-07",
        "nb_users":
        30,
        "instances": {
            "mgmt": {
                "type": "p4-6gb",
                "count": 1
            },
            "login": {
                "type": "p4-6gb",
                "count": 1
            },
            "node": {
                "type": "p2-3gb",
                "count": 12
            },
        },
        "storage": {
            "type": "nfs",
            "home_size": 400,
            "project_size": 12,
            "scratch_size": 50,
        },
        "public_keys": ["ssh-rsa FOOBAR"],
        "hieradata":
        "",
        "guest_passwd":
        "",
        "os_floating_ips": [],
    })
    modified_config.update_main_tf_json_file()
    saved_config = MagicCastleConfiguration.get_from_main_tf_json_file(
        "missingnodes.sub.example.com")
    assert saved_config.dump() == {
        "cluster_name": "missingnodes",
        "domain": "sub.example.com",
        "image": "CentOS-7-x64-2019-07",
        "nb_users": 30,
        "instances": {
            "mgmt": {
                "type": "p4-6gb",
                "count": 1
            },
            "login": {
                "type": "p4-6gb",
                "count": 1
            },
            "node": {
                "type": "p2-3gb",
                "count": 12
            },
        },
        "storage": {
            "type": "nfs",
            "home_size": 400,
            "project_size": 12,
            "scratch_size": 50,
        },
        "public_keys": ["ssh-rsa FOOBAR"],
        "hieradata": "",
        "guest_passwd": "",
        "os_floating_ips": ["100.101.102.103"],
    }
def test_get_from_dict_invalid_floating_ip():
    config = MagicCastleConfiguration.get_from_dict({
        "cluster_name":
        "foo",
        "domain":
        "calculquebec.cloud",
        "image":
        "CentOS-7-x64-2019-07",
        "nb_users":
        17,
        "instances": {
            "mgmt": {
                "type": "p4-6gb",
                "count": 1
            },
            "login": {
                "type": "p4-6gb",
                "count": 1
            },
            "node": {
                "type": "p2-3gb",
                "count": 3
            },
        },
        "storage": {
            "type": "nfs",
            "home_size": 50,
            "project_size": 1,
            "scratch_size": 1,
        },
        "public_keys": [""],
        "hieradata":
        "",
        "guest_passwd":
        '1234\\56789\t "',
        "os_floating_ips": ["4.4.4.4"],
    })
    assert config.dump() == {
        "cluster_name": "foo",
        "domain": "calculquebec.cloud",
        "image": "CentOS-7-x64-2019-07",
        "nb_users": 17,
        "instances": {
            "mgmt": {
                "type": "p4-6gb",
                "count": 1
            },
            "login": {
                "type": "p4-6gb",
                "count": 1
            },
            "node": {
                "type": "p2-3gb",
                "count": 3
            },
        },
        "storage": {
            "type": "nfs",
            "home_size": 50,
            "project_size": 1,
            "scratch_size": 1,
        },
        "public_keys": [""],
        "hieradata": "",
        "guest_passwd": '1234\\56789\t "',
        "os_floating_ips": [],
    }