def test_build_resources(self): resources = { "machines":[{ "address": "ip1", "roles": ["role1", "role2"] },{ "address": "ip2", "roles": ["role1"] }], "networks": [{ "cidr": "", "roles": ["net2"], "start": "2.2.3.100", "end": "2.2.3.252", "gateway": "2.2.3.254", "dns": "2.2.3.253" },{ "cidr": "1.2.3.4/24", "roles": ["net1"], "start": "1.2.3.100", "end": "1.2.3.252", "gateway": "1.2.3.254", "dns": "1.2.3.253" }] } conf = Configuration.from_dictionnary({"resources": resources}) s = Static(conf) roles, networks = s.init() self.assertCountEqual(["role1", "role2"], roles.keys()) self.assertEqual(2, len(roles["role1"])) self.assertEqual(1, len(roles["role2"])) self.assertEqual(2, len(networks)) self.assertTrue(networks[0]["cidr"] in ["1.2.3.4/24", ""])
def test_build_resources(self): resources = { "machines":[{ "address": "ip1", "roles": ["role1", "role2"] },{ "address": "ip2", "role": "role1" }], "networks": [{ "cidr": "cidr1", "roles": ["net1", "net2"] },{ "cidr": "cidr2", "role": "net1" }] } s = Static({"resources": resources}) roles, _ = s.init() self.assertItemsEqual(["role1", "role2"], roles.keys()) self.assertEquals(2, len(roles["role1"])) self.assertEquals(1, len(roles["role2"]))
"machines": [{ "roles": ["control"], "address": "localhost", "alias": "test_machine", "extra": { "ansible_connection": "local" } }], "networks": [{ "roles": ["local"], "start": "172.17.0.0", "end": "172.17.255.255", "cidr": "172.17.0.0/16", "gateway": "172.17.0.1", "dns": "172.17.0.1", }] } } inventory = os.path.join(os.getcwd(), "hosts") conf = Configuration.from_dictionnary(provider_conf) provider = Static(conf) roles, networks = provider.init() with play_on("all", roles=roles) as p: p.shell("date > /tmp/date") with open("/tmp/date") as f: print(f.readlines())
} } tc = {"enable": True, "default_delay": "20ms", "default_rate": "1gbit"} inventory = os.path.join(os.getcwd(), "hosts") print("Starting ressources with the provider vagrant") provider = Enos_vagrant(VagrantConf.from_dictionnary(provider_conf)) roles, networks = provider.init() print("Building the machine list") resources = {"machines": [], "networks": []} for role, machines in roles.items(): for machine in machines: resources["machines"].append({ "address": machine.address, "alias": machine.alias, "user": machine.user, "port": int(machine.port), "keyfile": machine.keyfile, "roles": [role], }) resources["networks"] = networks provider = Static(StaticConf.from_dictionnary({"resources": resources})) roles, networks = provider.init() discover_networks(roles, networks) netem = Netem(tc, roles=roles) netem.deploy() netem.validate()
"resources": { "machines": [{ "roles": ["control"], "alias": "test_machine", "address": "localhost", "extra": { "ansible_connection": "local" }, }], "networks": [{ "roles": ["local"], "start": "172.17.0.0", "end": "172.17.255.255", "cidr": "172.17.0.0/16", "gateway": "172.17.0.1", "dns": "172.17.0.1", }], } } inventory = os.path.join(os.getcwd(), "hosts") provider = Static(Configuration.from_dictionnary(provider_conf)) roles, networks = provider.init() generate_inventory(roles, networks, inventory, check_networks=True) # using an inventory result = run_command("date", pattern_hosts="control", inventory_path=inventory) print(json.dumps(result)) # using the roles result = run_command("date", pattern_hosts="control", roles=roles) print(json.dumps(result))
def up(env=None, **kwargs): conf = Configuration.from_dictionnary(provider_conf) provider = Static(conf) roles, networks = provider.init() env["roles"] = roles env["networks"] = networks
tc = { "enable": True, "default_delay": "20ms", "default_rate": "1gbit", } inventory = os.path.join(os.getcwd(), "hosts") print("Starting ressources with the provider vagrant") provider = Enos_vagrant(provider_conf) roles, networks = provider.init() print("Building the machine list") resources = {"machines": [], "networks": []} for role, machines in roles.items(): for machine in machines: resources["machines"].append({ "address": machine.address, "alias": machine.alias, "user": machine.user, "port": int(machine.port), "keyfile": machine.keyfile, "role": role }) resources["networks"] = networks provider = Static({"resources": resources}) roles, _ = provider.init() generate_inventory(roles, networks, inventory, check_networks=True) emulate_network(roles, inventory, tc) validate_network(roles, inventory)