def test_finish_action(self, spe_terminate_instance, spe_stop_instance):
        ssh = SSHCrossCloud(**self.command_arg)
        ssh.init_provider_specifics()
        ssh.ssh_params.final_state = 'stop'
        ssh.finish_action()
        spe_stop_instance.assert_called()

        ssh.ssh_params.final_state = 'terminate'
        ssh.finish_action()
        spe_terminate_instance.assert_called()
    def test_init_instance(self, spe_driver_create_instance,
                           spe_driver_spe_wait_until_running,
                           spe_driver_get_node):
        ssh = SSHCrossCloud(**self.command_arg)
        ssh.init_provider_specifics()
        ssh.init_instance(with_instance=True)
        spe_driver_get_node.assert_called()
        spe_driver_spe_wait_until_running.assert_called()

        ssh.init_instance(with_instance=False)
        spe_driver_get_node.assert_called()
        spe_driver_create_instance.assert_called()
    def test_manage_instance(self, spe_start_instance, ssh_init_instance):
        ssh = SSHCrossCloud(**self.command_arg)
        ssh.init_provider_specifics()
        ssh.manage_instance()
        ssh.ssh_params.sshcrosscloud_instance_id = None
        ssh_init_instance.assert_called_with(with_instance=False)

        ssh.ssh_params.instance_state = "stopped"
        ssh.manage_instance()
        spe_start_instance.assert_called()
        ssh_init_instance.assert_called_with(with_instance=True)

        ssh.ssh_params.instance_state = "unknown"
        with self.assertRaises(Exception):
            ssh.manage_instance()