Beispiel #1
0
 def test_parse_fail_2(self):
     containers = {
         "c1": {"ima": "image1", "command": "/bin/bash"},
         "c2": {"image": "image2", "links": ["c1"]}
     }
     d = dict(containers=containers)
     with self.assertRaises(BlockadeConfigError):
         BlockadeConfig.from_dict(d)
Beispiel #2
0
    def test_parse_with_start_delay_fail_nonnumeric(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash",
                   "start_delay": "abc123"}
        }
        d = dict(containers=containers, network={})

        with self.assertRaisesRegexp(BlockadeConfigError, "start_delay"):
            BlockadeConfig.from_dict(d)
Beispiel #3
0
    def test_parse_with_start_delay_fail_nonnumeric(self):
        containers = {
            "c1": {
                "image": "image1",
                "command": "/bin/bash",
                "start_delay": "abc123"
            }
        }
        d = dict(containers=containers, network={})

        with self.assertRaisesRegexp(BlockadeConfigError, "start_delay"):
            BlockadeConfig.from_dict(d)
Beispiel #4
0
 def test_parse_fail_2(self):
     containers = {
         "c1": {
             "ima": "image1",
             "command": "/bin/bash"
         },
         "c2": {
             "image": "image2",
             "links": ["c1"]
         }
     }
     d = dict(containers=containers)
     with self.assertRaises(BlockadeConfigError):
         BlockadeConfig.from_dict(d)
Beispiel #5
0
    def test_parse_with_start_delay_2(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash",
                   "start_delay": 0.4}
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.start_delay, 0.4)
Beispiel #6
0
    def test_parse_with_numeric_port(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash",
                   "expose": [10000]}
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.expose_ports, [10000])
Beispiel #7
0
    def test_parse_with_publish_1(self):
        containers = {
            "c1": {"image": "image1", "ports": {8080: 80}, "expose": [80]}
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.expose_ports, [80])
        self.assertEqual(c1.publish_ports, {'8080': '80'})
Beispiel #8
0
    def test_parse_with_multiple_cap_add(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash",
                   "cap_add": ["NET_ADMIN", "MKNOD"]}
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.cap_add, ["NET_ADMIN", "MKNOD"])
Beispiel #9
0
    def test_parse_2(self):
        containers = {"c1": {"image": "image1", "command": "/bin/bash"}}
        network = {"flaky": "61%"}
        d = dict(containers=containers, network=network)

        config = BlockadeConfig.from_dict(d)
        # default value should be there
        self.assertIn("flaky", config.network)
        self.assertEqual(config.network['flaky'], "61%")
        # default value should be there
        self.assertIn("slow", config.network)
Beispiel #10
0
    def test_parse_with_env_1(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash",
                   "environment": {"HATS": 4, "JACKETS": "some"}}
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.environment, {"HATS": "4", "JACKETS": "some"})
Beispiel #11
0
    def test_parse_with_name(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash",
                   "container_name": "abc"}
        }
        network = {}
        d = dict(containers=containers, network=network)

        config = BlockadeConfig.from_dict(d)
        # default value should be there
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.container_name, "abc")
Beispiel #12
0
    def test_parse_with_volumes_4(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash",
                   "volumes": {"/some/mount": None}}
        }
        network = {}
        d = dict(containers=containers, network=network)

        config = BlockadeConfig.from_dict(d)
        # default value should be there
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.volumes, {"/some/mount": "/some/mount"})
Beispiel #13
0
    def test_parse_2(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash"}
        }
        network = {"flaky": "61%"}
        d = dict(containers=containers, network=network)

        config = BlockadeConfig.from_dict(d)
        # default value should be there
        self.assertIn("flaky", config.network)
        self.assertEqual(config.network['flaky'], "61%")
        # default value should be there
        self.assertIn("slow", config.network)
Beispiel #14
0
    def test_parse_1(self):
        containers = {
            "c1": {"image": "image1", "command": "/bin/bash"},
            "c2": {"image": "image2", "links": ["c1"]}
        }
        d = dict(containers=containers)

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 2)
        self.assertEqual(config.containers["c1"].name, "c1")
        self.assertEqual(config.containers["c1"].image, "image1")
        self.assertEqual(config.containers["c1"].command, "/bin/bash")
        self.assertEqual(config.containers["c2"].name, "c2")
        self.assertEqual(config.containers["c2"].image, "image2")
Beispiel #15
0
    def test_parse_with_multiple_cap_add(self):
        containers = {
            "c1": {
                "image": "image1",
                "command": "/bin/bash",
                "cap_add": ["NET_ADMIN", "MKNOD"]
            }
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.cap_add, ["NET_ADMIN", "MKNOD"])
Beispiel #16
0
    def test_parse_with_start_delay_2(self):
        containers = {
            "c1": {
                "image": "image1",
                "command": "/bin/bash",
                "start_delay": 0.4
            }
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.start_delay, 0.4)
Beispiel #17
0
    def test_parse_with_numeric_port(self):
        containers = {
            "c1": {
                "image": "image1",
                "command": "/bin/bash",
                "expose": [10000]
            }
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.expose_ports, {"10000": "10000"})
Beispiel #18
0
    def test_parse_with_count_1(self):
        containers = {
            "db": {"image": "image1", "command": "/bin/bash", "count": 2},
            "app": {"image": "image1", "command": "/bin/bash",
                    "container_name": "abc", "count": 3}
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(set(config.containers.keys()),
                         set(["db_1", "db_2", "app_1", "app_2", "app_3"]))
        self.assertEqual(config.containers["app_1"].container_name, "abc_1")
        self.assertEqual(config.containers["app_2"].container_name, "abc_2")
        self.assertEqual(config.containers["app_3"].container_name, "abc_3")
Beispiel #19
0
    def test_parse_with_name(self):
        containers = {
            "c1": {
                "image": "image1",
                "command": "/bin/bash",
                "container_name": "abc"
            }
        }
        network = {}
        d = dict(containers=containers, network=network)

        config = BlockadeConfig.from_dict(d)
        # default value should be there
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.container_name, "abc")
Beispiel #20
0
    def test_parse_with_volumes_2(self):
        containers = {
            "c1": {
                "image": "image1",
                "command": "/bin/bash",
                "volumes": ["/some/mount"]
            }
        }
        network = {}
        d = dict(containers=containers, network=network)

        config = BlockadeConfig.from_dict(d)
        # default value should be there
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.volumes, {"/some/mount": "/some/mount"})
Beispiel #21
0
def create(name):
    if not request.headers['Content-Type'] == 'application/json':
        abort(415)

    if BlockadeManager.blockade_exists(name):
        return 'Blockade name already exists', 400

    # This will abort with a 400 if the JSON is bad
    data = request.get_json()
    config = BlockadeConfig.from_dict(data)
    BlockadeManager.store_config(name, config)

    b = BlockadeManager.get_blockade(name)
    containers = b.create()

    return '', 204
Beispiel #22
0
    def test_parse_with_publish_1(self):
        containers = {
            "c1": {
                "image": "image1",
                "ports": {
                    8080: 80
                },
                "expose": [80]
            }
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.expose_ports, [80])
        self.assertEqual(c1.publish_ports, {'8080': '80'})
Beispiel #23
0
    def test_parse_with_env_1(self):
        containers = {
            "c1": {
                "image": "image1",
                "command": "/bin/bash",
                "environment": {
                    "HATS": 4,
                    "JACKETS": "some"
                }
            }
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 1)
        c1 = config.containers['c1']
        self.assertEqual(c1.environment, {"HATS": 4, "JACKETS": "some"})
Beispiel #24
0
    def test_parse_1(self):
        containers = {
            "c1": {
                "image": "image1",
                "command": "/bin/bash"
            },
            "c2": {
                "image": "image2",
                "links": ["c1"]
            }
        }
        d = dict(containers=containers)

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(len(config.containers), 2)
        self.assertEqual(config.containers["c1"].name, "c1")
        self.assertEqual(config.containers["c1"].image, "image1")
        self.assertEqual(config.containers["c1"].command, "/bin/bash")
        self.assertEqual(config.containers["c2"].name, "c2")
        self.assertEqual(config.containers["c2"].image, "image2")
Beispiel #25
0
    def test_parse_with_count_1(self):
        containers = {
            "db": {
                "image": "image1",
                "command": "/bin/bash",
                "count": 2
            },
            "app": {
                "image": "image1",
                "command": "/bin/bash",
                "container_name": "abc",
                "count": 3
            }
        }
        d = dict(containers=containers, network={})

        config = BlockadeConfig.from_dict(d)
        self.assertEqual(set(config.containers.keys()),
                         set(["db_1", "db_2", "app_1", "app_2", "app_3"]))
        self.assertEqual(config.containers["app_1"].container_name, "abc_1")
        self.assertEqual(config.containers["app_2"].container_name, "abc_2")
        self.assertEqual(config.containers["app_3"].container_name, "abc_3")