def test_from_dictionnary_no_network(self):
        d = {
            "resources": {
                "machines": [{
                    "roles": ["r1"],
                    "nodes": 2,
                    "cluster": "cluste1",
                    "primary_network": "n1"
                }],
                "networks": []
            }
        }

        with self.assertRaises(ValueError) as _:
            Configuration.from_dictionnary(d)
    def test_from_dictionnary_with_machines(self):
        d = {
            "resources": {
                "machines": [{
                    "roles": ["r1"],
                    "nodes": 2,
                    "cluster": "cluste1",
                    "primary_network": "n1"
                }],
                "networks": [{
                    "id": "n1",
                    "roles": ["rn1"],
                    "site": "siteA",
                    "type": "prod"
                }]
            }
        }

        conf = Configuration.from_dictionnary(d)
        self.assertTrue(len(conf.machines) == 1)
        self.assertTrue(len(conf.networks) == 1)

        machine_group = conf.machines[0]
        network = conf.networks[0]

        self.assertEqual(2, machine_group.nodes)

        # check the network ref
        self.assertEqual(network, machine_group.primary_network)
    def test_from_dictionnary_unbound_secondary_networks(self):
        d = {
            "resources": {
                "machines": [{
                    "roles": ["r1"],
                    "nodes": 2,
                    "cluster": "cluste1",
                    "primary_network": "n1",
                    "secondary_networks": ["n2"]
                }],
                "networks": [{
                    "id": "network",
                    "roles": ["n1"],
                    "site": "siteA",
                    "type": "prod"
                }, {
                    "id": "unbound_network",
                    "roles": ["nr2"],
                    "site": "siteA",
                    "type": "kavlan"
                }]
            }
        }

        with self.assertRaises(ValueError) as ctx:
            conf = Configuration.from_dictionnary(d)
예제 #4
0
def g5k(config, force, env=None, **kwargs):
    conf = G5kConf.from_dictionnary(config["g5k"])
    provider = G5k(conf)
    roles, networks = provider.init(force_deploy=force)
    env["config"] = config
    env["roles"] = roles
    env["networks"] = networks
    env["context"] = "g5k"
예제 #5
0
 def destroy(self, env):
     conf = env.get('config')
     LOGGER.debug("Building enoslib configuration")
     enoslib_conf = _build_enoslib_conf(conf)
     conf = Configuration.from_dictionnary(enoslib_conf)
     LOGGER.debug("Creating G5K provider")
     g5k = provider.G5k(conf)
     LOGGER.info("Destroying G5K deployment")
     g5k.destroy()
예제 #6
0
 def init(self, config, force=False):
     LOGGER.debug("Building enoslib configuration")
     enoslib_conf = _build_enoslib_conf(config)
     conf = Configuration.from_dictionnary(enoslib_conf)
     LOGGER.debug("Creating G5K provider")
     g5k = provider.G5k(conf)
     LOGGER.info("Initializing G5K provider")
     roles, networks = g5k.init(force)
     _provision(roles)
     return roles, networks
예제 #7
0
 def test_from_dictionnary_minimal(self):
     d = {"resources": {"machines": [], "networks": []}}
     conf = Configuration.from_dictionnary(d)
     self.assertEqual(constants.DEFAULT_ENV_NAME, conf.env_name)
     self.assertEqual(constants.DEFAULT_JOB_NAME, conf.job_name)
     self.assertEqual(constants.DEFAULT_JOB_TYPE, conf.job_type)
     self.assertEqual(constants.DEFAULT_QUEUE, conf.queue)
     self.assertEqual(constants.DEFAULT_WALLTIME, conf.walltime)
     self.assertEqual([], conf.machines)
     self.assertEqual([], conf.networks)
예제 #8
0
    def test_from_dictionnary_unbound_network(self):
        d = {
            "resources": {
                "machines": [{
                    "roles": ["r1"],
                    "nodes": 2,
                    "cluster": "cluste1",
                    "primary_network": "n1",
                }],
                "networks": [{
                    "id": "unbound_network",
                    "roles": ["rn1"],
                    "site": "siteA",
                    "type": "prod",
                }],
            }
        }

        with self.assertRaises(ValueError) as _:
            Configuration.from_dictionnary(d)
 def test_from_dictionnary_some_metadatas(self):
     d = {
         "job_name": "test",
         "queue": "production",
         "resources": {
             "machines": [],
             "networks": []
         }
     }
     conf = Configuration.from_dictionnary(d)
     self.assertEqual(constants.DEFAULT_ENV_NAME, conf.env_name)
     self.assertEqual("test", conf.job_name)
     self.assertEqual(constants.DEFAULT_JOB_TYPE, conf.job_type)
     self.assertEqual("production", conf.queue)
     self.assertEqual(constants.DEFAULT_WALLTIME, conf.walltime)
예제 #10
0
def make_conf(testing=True) -> Configuration:
    conf = {
        "reservation": "2021-03-05 07:00:01",
        "walltime": "11:59:58",
        "job_name": "lab-2021-imta-fise-login-os",
        "env_name": "ubuntu2004-x64-min",
        "project": "lab-2021-imta-fise-login-os",
        "resources": {
            "networks": [
                {
                    "id": "net",
                    "type": "prod",
                    "roles": ["network_interface"],
                    "site": "rennes",
                },
                # Keep this for future work, for a deployment
                # based OpenStack.
                # {
                #     # Note: *NEVER* assigns this to a machine!
                #     "id": "net_ext",
                #     "type": "slash_22",
                #     "roles": ["neutron_external_interface"],
                #     "site": "rennes",
                # },
            ],
            "machines": [{
                "roles": ["OpenStack"],
                "cluster": "paravance",
                "nodes": 13,
                "primary_network": "net",
                "secondary_networks": [],
            }],
        }
    }

    if testing:
        del (conf["reservation"])
        conf["walltime"] = "07:00:00"
        conf["job_name"] = "test-lab-2021-imta-fise-login-os"
        conf["resources"]["machines"][0]["nodes"] = 1

    return Configuration.from_dictionnary(conf)
예제 #11
0
    def test_from_dictionnary_with_machines_and_secondary_networks(self):
        d = {
            "resources": {
                "machines": [{
                    "roles": ["r1"],
                    "nodes": 2,
                    "cluster": "cluste1",
                    "primary_network": "n1",
                    "secondary_networks": ["n2"],
                }],
                "networks": [
                    {
                        "id": "n1",
                        "roles": ["rn1"],
                        "site": "siteA",
                        "type": "prod"
                    },
                    {
                        "id": "n2",
                        "roles": ["rn2"],
                        "site": "siteA",
                        "type": "kavlan"
                    },
                ],
            }
        }

        conf = Configuration.from_dictionnary(d)
        self.assertTrue(len(conf.machines) == 1)
        self.assertTrue(len(conf.networks) == 2)

        machine_group = conf.machines[0]
        networks = conf.networks

        self.assertEqual(2, machine_group.nodes)

        # check the network ref
        self.assertTrue(machine_group.primary_network in networks)
        self.assertEqual("n1", machine_group.primary_network.id)
        self.assertEqual(1, len(machine_group.secondary_networks))
        self.assertTrue(machine_group.secondary_networks[0] in networks)
        self.assertEqual("n2", machine_group.secondary_networks[0].id)
예제 #12
0
            "nodes": 1,
            "primary_network": "n1",
            "secondary_networks": ["n2"]
        }],
        "networks": [{
            "id": "n1",
            "type": "kavlan",
            "roles": ["my_network"],
            "site": "rennes",
         }, {
            "id": "n2",
            "type": "kavlan",
            "roles": ["my_second_network"],
            "site": "rennes",
         }]
    }
}

# path to the inventory
inventory = os.path.join(os.getcwd(), "hosts")

# claim the resources
conf = Configuration.from_dictionnary(provider_conf)
provider = G5k(conf)
roles, networks = provider.init()

# generate an inventory compatible with ansible
generate_inventory(roles, networks, inventory, check_networks=True)

# destroy the reservation