def _new_provider(self, provider_config=None, UserData=""): provider_config = provider_config or util.ProviderConfig({}, {}) a4bucket = { "maxCount": 2, "activeCount": 0, "definition": { "machineType": "A4" }, "virtualMachine": MACHINE_TYPES["A4"] } a8bucket = { "maxCoreCount": 24, "activeCount": 0, "definition": { "machineType": "A8" }, "virtualMachine": MACHINE_TYPES["A8"] } cluster = MockCluster({ "nodearrays": [{ "name": "execute", "UserData": UserData, "nodearray": { "machineType": ["a4", "a8"], "Interruptible": False, "Configuration": { "autoscaling": { "enabled": True }, "symphony": { "autoscale": True } } }, "buckets": [a4bucket, a8bucket] }, { "name": "lp_execute", "UserData": UserData, "nodearray": { "machineType": ["a4", "a8"], "Interruptible": True, "Configuration": { "autoscaling": { "enabled": True }, "symphony": { "autoscale": True } } }, "buckets": [a4bucket, a8bucket] }] }) epoch_clock = MockClock((1970, 1, 1, 0, 0, 0)) hostnamer = MockHostnamer() provider = cyclecloud_provider.CycleCloudProvider( provider_config, cluster, hostnamer, json_writer, RequestsStoreInMem(), RequestsStoreInMem(), epoch_clock) provider.capacity_tracker.reset() return provider
def test_custom_env(self): config = util.ProviderConfig({}, {}) provider = self._new_provider(config) config.set("templates.default.UserData", "abc=123;def=1==1") self.assertEquals({"abc": "123", "def": "1==1"}, provider.templates()["templates"][0]["UserData"]["symphony"]["custom_env"]) self.assertEquals("abc def", provider.templates()["templates"][0]["UserData"]["symphony"]["custom_env_names"]) config.set("templates.default.UserData", "abc=123;def=1==1;") self.assertEquals({"abc": "123", "def": "1==1"}, provider.templates()["templates"][0]["UserData"]["symphony"]["custom_env"]) self.assertEquals("abc def", provider.templates()["templates"][0]["UserData"]["symphony"]["custom_env_names"]) config.set("templates.default.UserData", "abc=123;def=1==1;bad_form") self.assertEquals({"abc": "123", "def": "1==1"}, provider.templates()["templates"][0]["UserData"]["symphony"]["custom_env"]) self.assertEquals("abc def", provider.templates()["templates"][0]["UserData"]["symphony"]["custom_env_names"]) config.set("templates.default.UserData", "abc=123;def=1==1;good_form=234;bad_form_123") self.assertEquals({"abc": "123", "def": "1==1", "good_form": "234"}, provider.templates()["templates"][0]["UserData"]["symphony"]["custom_env"]) self.assertEquals("abc def good_form", provider.templates()["templates"][0]["UserData"]["symphony"]["custom_env_names"]) def assert_no_user_data(): templates = provider.templates() self.assertNotIn("custom_env", templates["templates"][0]["UserData"]["symphony"]) self.assertNotIn("custom_env_names", templates["templates"][0]["UserData"]["symphony"]) config.set("templates.default.UserData", ";") assert_no_user_data() config.set("templates.default.UserData", None) assert_no_user_data() config.set("templates.default.UserData", "all;around;bad") assert_no_user_data()
def test_provider_config(self): self.assertEquals( "d", util.ProviderConfig({ "a": { "b": { "c": "d" } } }, {}).get("a.b.c")) self.assertEquals({"c": "d"}, util.ProviderConfig({ "a": { "b": { "c": "d" } } }, {}).get("a.b")) # missing from user config, look in jetpack self.assertEquals( "y", util.ProviderConfig({ "a": { "b": { "c": "d" } } }, { "x": "y" }).get("x")) # fall back on default_value, if all else fails self.assertEquals( "0", util.ProviderConfig({}, { "x": "y" }).get("z.a.b", "0")) # user config overrides jetpack self.assertEquals( "d", util.ProviderConfig({ "a": { "b": { "c": "d" } } }, { "a": { "b": { "c": "e" } } }).get("a.b.c")) pc = util.ProviderConfig({}, {}) pc.set("a", "b") self.assertEquals("b", pc.get("a")) pc.set("x.y.z", "123") self.assertEquals("123", pc.get("x.y.z")) self.assertEquals({"z": "123"}, pc.get("x.y")) self.assertEquals({"y": {"z": "123"}}, pc.get("x")) self.assertEquals({"x": {"y": {"z": "123"}}, "a": "b"}, pc.get("")) self.assertEquals({"x": {"y": {"z": "123"}}, "a": "b"}, pc.get(None))