Exemplo n.º 1
0
class VagrantChaosTests(unittest.TestCase):
    def setUp(self):
        #defaults to vagrantfile in current directory
        self.vagrant_chaos = VagrantChaos()
        self.node_ip = "172.28.128.199"
        self.node_name = "node1"

    def tearDown(self):
        #cleanup everything
        #halting the machines makes test iteration a bit faster
        #for a more serious deployment change this to
        #self.vagrant_instance.destroy()
        #self.vagrant_instance.halt()
        pass

    def test_turn_on(self):
        self.vagrant_chaos.turn_on_node(self.node_name)
        status_list = self.vagrant_chaos.status()
        name_list = []
        for status in status_list:
            if status.state == 'running':
                name_list.append(status.name)
        self.assertEqual(name_list, ["node1"])

    def test_active_nodes_list(self):
        self.vagrant_chaos.turn_on_node(self.node_name)
        status_list = self.vagrant_chaos.status()
        name_list = self.vagrant_chaos.active_nodes_list()
        self.assertEqual(name_list, ["node1"])

    def test_turn_off(self):
        self.vagrant_chaos.turn_on_node(self.node_name)
        node_state = self.vagrant_chaos.vagrant_instance.status(vm_name = self.node_name)[0].state
        self.assertEqual(node_state, "running")
        self.vagrant_chaos.turn_off_node(self.node_name)

        node_state = self.vagrant_chaos.vagrant_instance.status(vm_name = self.node_name)[0].state
        self.assertEqual(node_state, "poweroff")