Example #1
0
    def test_cluster_worker_ensure_cluster_up(self):
        with Shim(sut) as manager:
            with Shim(sut.ClusterWorker) as Worker:

                class FakeCmd:
                    UP = object()

                    @assertCalled(self, 1)
                    def __init__(this, action, project, files):
                        pass

                    @assertCalled(self, 1)
                    def run(self):
                        pass

                @assertCalled(self, 1)
                def bridge_link_if_ready(this, user, vpn, cluster):
                    self.assertEqual(self.vpn.id, vpn.id)
                    self.assertEqual(self.user.id, user.id)
                    self.assertEqual(DB.Cluster(user, vpn).id, cluster.id)

                Worker.bridge_link_if_ready = bridge_link_if_ready

                manager.ComposeCmd = FakeCmd

                cluster = DB.Cluster(self.user, self.vpn)
                cluster.delete()

                worker = manager.ClusterWorker('foo', 'bar')
                worker.ensure_cluster_up(self.user, self.vpn, cluster,
                                         self.connection)
                worker.ensure_cluster_up(self.user, self.vpn, cluster,
                                         self.connection)

                self.assertEqual(cluster.status, 'up')
Example #2
0
    def test_cluster_worker_ensure_cluster_stopped(self):
        with Shim(sut) as manager:

            class FakeCmd:
                STOP = object()

                @assertCalled(self, 1)
                def __init__(this, action, project, files):
                    pass

                @assertCalled(self, 1)
                def run(self):
                    pass

            manager.ComposeCmd = FakeCmd

            cluster = DB.Cluster(self.user, self.vpn)
            cluster.delete()

            worker = manager.ClusterWorker('foo', 'bar')
            worker.ensure_cluster_stopped(self.user, self.vpn, cluster)

            cluster.status = 'up'
            worker.ensure_cluster_stopped(self.user, self.vpn, cluster)
            self.assertEqual(cluster.status, 'stopped')

            worker.ensure_cluster_stopped(self.user, self.vpn, cluster)

            self.assertEqual(cluster.status, 'stopped')
Example #3
0
    def test_vlan_worker_bridge_cluster(self):
        with Shim(sut) as manager:

            class FakeCmd:
                ADDIF = object()

                @assertCalled(self, 1)
                def __init__(this, action, bridge_id, vlan_if):
                    pass

                @assertCalled(self, 1)
                def run(self):
                    pass

            manager.BrctlCmd = FakeCmd
            manager.get_bridge_id = lambda cluster_id: "bogus"  # The real function requires docker

            cluster = DB.Cluster(self.user, self.vpn)

            self.vpn.links[self.user.vlan] = 'up'

            worker = manager.VlanWorker('foo', 'bar')
            worker.bridge_cluster(self.vpn, self.user)

            self.assertNotEqual(self.vpn.links[self.user.vlan], 'bridged')

            cluster.status = "up"
            worker.bridge_cluster(self.vpn, self.user)

            self.assertEqual(self.vpn.links[self.user.vlan], 'bridged')
Example #4
0
    def setUp(self):
        self.redis.flushall()

        self.vpn = DB.Vpn('0123456789ab')
        self.vpn.update(veth="fakeveth", veth_state="down")
        self.vpn.files.extend(["test-compose.yml"])

        self.vpn = DB.Vpn('0123456789ab')
        self.vpn.update(veth="fakeveth", veth_state="down")

        self.user = DB.User('auserid')
        self.user.update(vlan=4000, cn='ausername', status="active")

        self.addr = Address('127.0.0.1', 42)
        self.connection = DB.Connection(self.addr)
        self.connection.update(addr=self.addr,
                               alive=True,
                               user=self.user,
                               vpn=self.vpn)

        self.cluster = None

        self.user.connections.add(self.connection)
        self.vpn.links[4000] = 'bridged'
Example #5
0
    def test_cluster_worker_bridge_link_if_ready(self):
        with Shim(sut) as manager:

            class FakeBrctlCmd:
                ADDIF = object()

                @assertCalled(self, 1)
                def __init__(this, action, bridge_id, vlan_if):
                    pass

                @assertCalled(self, 1)
                def run(self):
                    pass

            manager.BrctlCmd = FakeBrctlCmd

            class FakeIpFlushCmd:
                @assertCalled(self)
                def __init__(this, bridge_id):
                    pass

                @assertCalled(self)
                def run(self):
                    pass

            manager.IpFlushCmd = FakeIpFlushCmd
            manager.get_bridge_id = lambda cluster_id: "bogus"  # The real function requires docker

            cluster = DB.Cluster(self.user, self.vpn)
            cluster.delete()

            self.vpn.links[self.user.vlan] = 'down'

            worker = manager.ClusterWorker('foo', 'bar')
            worker.bridge_link_if_ready(self.user, self.vpn, cluster)
            self.assertEqual(self.vpn.links[self.user.vlan], 'down')

            self.vpn.links[self.user.vlan] = 'up'
            worker.bridge_link_if_ready(self.user, self.vpn, cluster)
            self.assertEqual(self.vpn.links[self.user.vlan], 'bridged')

            worker.bridge_link_if_ready(self.user, self.vpn, cluster)
            self.assertEqual(self.vpn.links[self.user.vlan], 'bridged')
Example #6
0
 def bridge_link_if_ready(this, user, vpn, cluster):
     self.assertEqual(self.vpn.id, vpn.id)
     self.assertEqual(self.user.id, user.id)
     self.assertEqual(DB.Cluster(user, vpn).id, cluster.id)
Example #7
0
 def ensure_cluster_stopped(worker, user, vpn, cluster):
     self.assertEqual(self.vpn.id, vpn.id)
     self.assertEqual(self.user.id, user.id)
     self.assertEqual(DB.Cluster(user, vpn).id, cluster.id)
Example #8
0
 def ensure_cluster_up(worker, user, vpn, cluster, connection):
     self.assertEqual(self.vpn.id, vpn.id)
     self.assertEqual(self.user.id, user.id)
     self.assertEqual(DB.Cluster(user, vpn).id, cluster.id)
     self.assertEqual(self.connection.id, connection.id)