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')
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')
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')
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')
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)
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)
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)