예제 #1
0
    def test_aws_utils(self):
        if not USING_PYTHON2:
            self.assertTrue(
                isinstance(get_ondemand_price_usd("us-east-1", "t2.micro"),
                           str))
        self.assertEquals(str(ARN(region="", account_id="")), "arn:aws::::")
        self.assertTrue(str(ARN()).startswith("arn:aws:"))
        self.assertEquals(str(ARN("arn:aws:foo:bar:xyz:zzt")),
                          "arn:aws:foo:bar:xyz:zzt")
        self.assertEquals(
            str(
                ARN("arn:aws:a:b:c:d",
                    service="x",
                    region="us-west-1",
                    account_id="1",
                    resource="2")), "arn:aws:x:us-west-1:1:2")
        get_user_data(commands=["ls"], packages=["foo"], files=["bar"])

        # Test serialization of tweak.Config objects
        from tweak import Config
        d = dict(x={}, y=[1, 2])
        c = Config(save_on_exit=False, _parent=self, _data=d)

        aegea.util.aws.dns.config = c
        c.dns = {}
        c.dns.private_zone = "aegea.test"
        with self.assertRaises(AegeaException):
            aegea.util.aws.dns.DNSZone(create_default_private_zone=False)
        with self.assertRaises(AegeaException):
            aegea.util.aws.dns.DNSZone(zone_name="foobar",
                                       create_default_private_zone=False)

        self.assertEquals(get_user_data(foo=c, bar=2),
                          get_user_data(bar=2, foo=c))
        # ensure_s3_bucket()
        self.assertEqual(encode_tags(["foo=bar"]), [{
            'Key': 'foo',
            'Value': 'bar'
        }])
        self.assertEqual(encode_tags(dict(foo="bar")), [{
            'Key': 'foo',
            'Value': 'bar'
        }])
        self.assertEqual(decode_tags([dict(Key="foo", Value="bar")]),
                         {'foo': 'bar'})
        filter_by_tags(resources.ec2.instances, Name="")
        self.assertEqual(get_bdm(), [
            dict(VirtualName="ephemeral" + str(i),
                 DeviceName="xvd" + chr(ord("b") + i)) for i in range(12)
        ])
        # for instance in resources.ec2.instances.all():
        #     get_iam_role_for_instance(instance.id)
        #     break
        make_waiter(clients.efs.describe_file_systems,
                    "FileSystems[].LifeCycleState", "available", "pathAny")
예제 #2
0
파일: test.py 프로젝트: kislyuk/tweak
 def test_basic_statements2(self):
     config = Config()
     config.test = 1
     config.test2 = True
     config.test3 = None
     config.test4 = dict(x=1, y=2)
     print(config.test4.x)
     config.test4.x = "тест"
     print(config.test4.x)
     config.test4.save()
     print(config)
예제 #3
0
파일: test.py 프로젝트: kislyuk/tweak
    def test_basic_statements(self):
        config = Config()
        print(config)
        config.host, config.port = "example.com", 9000
        config.nested_config = {}
        config.nested_config.foo = True
        config.nested_config.bar = 9000
        print(config)
        if "token" not in config:
            config["token"] = "т"

        import argparse

        parser = argparse.ArgumentParser(description=__doc__)
        for arg in "verbose quiet failfast catch buffer".split():
            parser.add_argument("-" + arg[0], "--" + arg, nargs="?")
        parser.add_argument("--foo")
        parser.add_argument("--bar")
        args = parser.parse_args()
        config.update(vars(args))
        print(config)

        config = Config(save_on_exit=True, autosave=False, use_yaml=True)
        config.foo = "bar"
        config.nested_config = {}
        config.nested_config.foo = True
        config.nested_config.bar = 9001
        config.nested_config.baz = "т"
예제 #4
0
    def test_aws_utils(self):
        self.assertTrue(isinstance(get_ondemand_price_usd("us-east-1", "t2.micro"), str))
        self.assertEquals(str(ARN(region="", account_id="")), "arn:aws::::")
        self.assertTrue(str(ARN()).startswith("arn:aws:"))
        self.assertEquals(str(ARN("arn:aws:foo:bar:xyz:zzt")), "arn:aws:foo:bar:xyz:zzt")
        self.assertEquals(str(ARN("arn:aws:a:b:c:d", service="x", region="us-west-1", account_id="1", resource="2")),
                          "arn:aws:x:us-west-1:1:2")
        with self.assertRaises(AegeaException):
            DNSZone(use_unique_private_zone=False)
        get_user_data(commands=["ls"], packages=["foo"], files=["bar"])

        # Test serialization of tweak.Config objects
        from tweak import Config
        d = dict(x={}, y=[1, 2])
        c = Config(save_on_exit=False, _parent=self, _data=d)
        self.assertEquals(get_user_data(foo=c, bar=2), get_user_data(bar=2, foo=c))
예제 #5
0
파일: test.py 프로젝트: kislyuk/tweak
 def test_merge(self):
     config = Config()
     config.update({})
     config.update({"m": {"i": 1}})
     self.assertEqual(config["m"], {"i": 1})
     config.update({"m": {"j": 2}})
     self.assertEqual(config["m"], {"i": 1, "j": 2})
     config.update({"m": {"j": [7, 8]}})
     self.assertEqual(config["m"], {"i": 1, "j": [7, 8]})
     config.update({"m": {"k": []}})
     self.assertEqual(config["m"], {"i": 1, "j": [7, 8], "k": []})
     config.update({"m": {"k": {"$append": "v"}}})
     self.assertEqual(config["m"], {"i": 1, "j": [7, 8], "k": ["v"]})
     config.update({"m": {"k": {"$append": "v"}}})
     self.assertEqual(config["m"], {"i": 1, "j": [7, 8], "k": ["v", "v"]})
     config.update({"m": {"k": {"$extend": ["z", "z"]}}})
     self.assertEqual(config["m"], {"i": 1, "j": [7, 8], "k": ["v", "v", "z", "z"]})
     config.update({"m": {"k": {"$extendleft": ["z", "z"]}}})
     self.assertEqual(config["m"], {"i": 1, "j": [7, 8], "k": ["z", "z", "v", "v", "z", "z"]})
     config.update({"m": {"k": {"$insert": {0: 5}}}})
     self.assertEqual(config["m"], {"i": 1, "j": [7, 8], "k": [5, "z", "z", "v", "v", "z", "z"]})
     config.update({"m": {"k": {"$remove": "z"}}})
     self.assertEqual(config["m"], {"i": 1, "j": [7, 8], "k": [5, "z", "v", "v", "z", "z"]})