def test(self):
        self.do_preliminary_cleanup()
        with open(join(self.base_dir, 'target'), 'w') as target_file:
            target_file.write(root_target_contents)
        os.makedirs(self.subtarget_folder)
        with open(join(self.subtarget_folder, 'target'), 'w') as subtarget_file:
            subtarget_file.write(sub_target_contents)
        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('foo.bar01').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('foo.bar01'))
            when.calling('ssh').at_least_with_arguments('foo.bar02').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('foo.bar02'))

        return_code = self.execute_command('yadtshell status -v')

        self.assertEqual(0, return_code)
        with self.verify() as complete_verify:

            with complete_verify.filter_by_argument('foo.bar01') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'foo.bar01').and_input('/usr/bin/yadt-status')
            with complete_verify.filter_by_argument('foo.bar02') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'foo.bar02').and_input('/usr/bin/yadt-status')

            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('it01.domain', template=template_it01_domain))
            when.calling('ssh').at_least_with_arguments(
                'it01.domain').then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('it02.domain', template=template_it02_domain))
            when.calling('ssh').at_least_with_arguments(
                'it02.domain').then_return(0)

        status_return_code = self.execute_command('yadtshell status')
        update_return_code = self.execute_command(
            'yadtshell update host://it01 --no-final-status')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').with_input('/usr/bin/yadt-status')
            verify.called('ssh').with_input('/usr/bin/yadt-status')

            self.assertEqual(0, update_return_code)
            # status before update
            verify.called('ssh').with_input('/usr/bin/yadt-status')
            verify.called('ssh').with_input('/usr/bin/yadt-status')

            verify.called('ssh').at_least_with_arguments(
                '-O', 'check')
            verify.called('ssh').at_least_with_arguments(
                '-O', 'check')

            # prestart of it01.domain services w/o dependencies
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start bar_service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status bar_service')

            # prestart of it02.domain services that are needed
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-start ham_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-status ham_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-start spam_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-status spam_service')

            # prestart of the it01.domain service that had the it02 dependency
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start foo_service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status foo_service')

            # the eggs_service has NOT been started

            # update
            verify.called('ssh').at_least_with_arguments(
                'yadt-command yadt-host-update yat-0:0.0.8 foo-0:0.0.0', 'it01.domain')
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('it01.domain', template=template_it01_domain))
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('it02.domain', template=template_it02_domain))

            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status foo_service').then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status spam_service').then_return(3).then_return(0)

            when.calling('ssh').at_least_with_arguments('it02.domain').then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain').then_return(0)

        status_return_code = self.execute_command('yadtshell status')
        update_return_code = self.execute_command(
            'yadtshell update host://it02 --no-final-status -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').with_input('/usr/bin/yadt-status')
            verify.called('ssh').with_input('/usr/bin/yadt-status')

            self.assertEqual(0, update_return_code)
            # status before update
            verify.called('ssh').with_input('/usr/bin/yadt-status')
            verify.called('ssh').with_input('/usr/bin/yadt-status')

            verify.called('ssh').at_least_with_arguments(
                '-O', 'check')
            verify.called('ssh').at_least_with_arguments(
                '-O', 'check')

            # stop
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-stop foo_service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status foo_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-stop spam_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-status spam_service')

            # update
            verify.called('ssh').at_least_with_arguments(
                'yadt-command yadt-host-update yat-0:0.0.8 foo-0:0.0.0', 'it02.domain')

            # start
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-start spam_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-status spam_service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start foo_service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status foo_service')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        actual_return_code = self.execute_command('yadtshell update -v')

        self.assertEqual(0, actual_return_code)

        with self.verify() as verify:
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')
            verify.called('ssh').at_least_with_arguments('-l').at_least_one_argument_matches(
                '\d{4}-\d{2}-\d{2}/yadtshell.integration-test.\d{4}-\d{2}-\d{2}--\d{2}-\d{2}-\d{2}.*\.001\.it01\.backend-service_start\.log')
            verify.called('ssh').at_least_with_arguments('-l').at_least_one_argument_matches(
                '\d{4}-\d{2}-\d{2}/yadtshell.integration-test.\d{4}-\d{2}-\d{2}--\d{2}-\d{2}-\d{2}.*\.002\.it01\.backend-service_status\.log')
            verify.called('ssh').at_least_with_arguments('-l').at_least_one_argument_matches(
                '\d{4}-\d{2}-\d{2}/yadtshell.integration-test.\d{4}-\d{2}-\d{2}--\d{2}-\d{2}-\d{2}.*\.003\.it01\.frontend-service_start\.log')
            verify.called('ssh').at_least_with_arguments('-l').at_least_one_argument_matches(
                '\d{4}-\d{2}-\d{2}/yadtshell.integration-test.\d{4}-\d{2}-\d{2}--\d{2}-\d{2}-\d{2}.*\.004\.it01\.frontend-service_status\.log')
            verify.called('ssh').at_least_with_arguments('-l').at_least_one_argument_matches(
                '\d{4}-\d{2}-\d{2}/yadtshell.integration-test.\d{4}-\d{2}-\d{2}--\d{2}-\d{2}-\d{2}.*\.005\.it01\.it01_update\.log')
            verify.called('ssh').at_least_with_arguments('-l').at_least_one_argument_matches(
                '\d{4}-\d{2}-\d{2}/yadtshell.integration-test.\d{4}-\d{2}-\d{2}--\d{2}-\d{2}-\d{2}.*\.006\.it01\.log')
Esempio n. 5
0
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        update_return_code = self.execute_command(
            'yadtshell updateartefact artefact://it01/yit-config-it01 -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(0, update_return_code)
            verify.called('ssh').at_least_with_arguments(
                '-O', 'check', 'it01.domain')
            verify.called('ssh').at_least_with_arguments(
                'yadt-command yadt-artefact-update yit-config-it01',
                'it01.domain')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        stop_return_code = self.execute_command(
            'yadtshell stop service://* -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(1, stop_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-stop frontend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status frontend-service')
Esempio n. 7
0
    def test(self):
        self.write_target_file('it01.domain', 'unreachable.host.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain').then_return(0)
            when.calling('ssh').at_least_with_arguments('unreachable.host.domain').then_return(255)

        status_return_code = self.execute_command('yadtshell status -v --ignore-unreachable-hosts')
        lock_return_code = self.execute_command(
            'yadtshell lock host://* -m "locking the hosts" -v --no-final-status --ignore-unreachable-hosts')

        self.assertEqual(0, status_return_code)
        self.assertEqual(0, lock_return_code)

        with self.verify() as verify:
            with verify.filter_by_argument('it01.domain') as it01_verify:

                it01_verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

                it01_verify.called('ssh').at_least_with_arguments(
                    'it01.domain', "yadt-command yadt-host-lock 'locking the hosts'")
            verify.finished()
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=STATUS_TEMPLATE))
            when.calling('ssh').at_least_with_arguments(
                'foo',
                'yadt-command yadt-service-status readonly').then_return(3)
            when.calling('ssh').at_least_with_arguments(
                'it01.domain').then_return(0)

        status_return_code = self.execute_command('yadtshell status')
        start_return_code = self.execute_command(
            'yadtshell start service://it01/service -v')

        self.assertEqual(0, status_return_code)
        self.assertEqual(1, start_return_code)

        with self.verify() as verify:

            # fetch full initial status + readonly information
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments(
                'foo', 'yadt-command yadt-service-status readonly')

            # SSH multiplexing
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')

            # check if dependent readonly service is still running
            verify.called('ssh').at_least_with_arguments(
                'foo', 'yadt-command yadt-service-status readonly')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        self.execute_command('yadtshell status -v')
        lock1_return_code = self.execute_command(
            'yadtshell lock host://it01 -m "locking" -v --session-id my_id')

        self.assertEqual(0, lock1_return_code)

        with self.verify() as verify:
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain', "yadt-command yadt-host-lock 'locking'"
            ).at_least_one_argument_matches('WHO=[a-zA-Z0-9_]+\@my_id')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
Esempio n. 10
0
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        unignore_return_code = self.execute_command(
            'yadtshell unignore service://* -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(0, unignore_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-unignore backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-unignore frontend-service')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status backend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        actual_return_code = self.execute_command('yadtshell update -v')

        self.assertEqual(1, actual_return_code)

        with self.verify() as verify:
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-start backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status backend-service')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=yadt_status_answer.STATUS_JSON_TEMPLATE))

        actual_return_code = self.execute_command('yadtshell status')
        self.assertEqual(0, actual_return_code)

        self.assertEqual(0, self.execute_command(
            'yadtshell info | grep " u " | grep "host uptodate"'))
        return_code, stdout, _ = self.execute_command_and_capture_output(
            'yadtshell info')
        update_found_for_foo = False
        for line in stdout.splitlines():
            if re.search('\(next\) foo', line):
                update_found_for_foo = True
                break
        self.assertTrue(
            update_found_for_foo, 'yit not obsoleted by foo, info was:{0}'.format(stdout))

        self.assertEqual(0, self.execute_command(
            'yadtshell dump --show-pending-updates | grep foo'))

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        self.execute_command('yadtshell status -v')
        lock1_return_code = self.execute_command(
            'yadtshell lock host://it01 -m "locking" -v --session-id my_id')

        self.assertEqual(0, lock1_return_code)

        with self.verify() as verify:
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain', "yadt-command yadt-host-lock 'locking'").at_least_one_argument_matches(
                'WHO=[a-zA-Z0-9_]+\@my_id')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        lock_return_code = self.execute_command(
            'yadtshell lock host://it01 -m "locking the höst!" -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)

            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(0, lock_return_code)

            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                u"yadt-command yadt-host-lock 'locking the höst!'")

            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=STATUS_TEMPLATE))
            when.calling('ssh').at_least_with_arguments('foo',
                                                        'yadt-command yadt-service-status readonly').then_return(3)
            when.calling('ssh').at_least_with_arguments('it01.domain').then_return(0)

        status_return_code = self.execute_command('yadtshell status')
        start_return_code = self.execute_command('yadtshell start service://it01/service -v')

        self.assertEqual(0, status_return_code)
        self.assertEqual(1, start_return_code)

        with self.verify() as verify:

            # fetch full initial status + readonly information
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments('foo',
                                                         'yadt-command yadt-service-status readonly')

            # SSH multiplexing
            verify.called('ssh').at_least_with_arguments('it01.domain', '-O', 'check')

            # check if dependent readonly service is still running
            verify.called('ssh').at_least_with_arguments('foo',
                                                         'yadt-command yadt-service-status readonly')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        update_return_code = self.execute_command(
            'yadtshell updateartefact artefact://it01/yit-config-it01 -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(0, update_return_code)
            verify.called('ssh').at_least_with_arguments(
                '-O', 'check', 'it01.domain')
            verify.called('ssh').at_least_with_arguments(
                'yadt-command yadt-artefact-update yit-config-it01', 'it01.domain')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', reboot_required_to_activate_latest_kernel=True))
            when.calling('ssh').at_least_with_arguments('it01.domain').then_return(0)

        actual_return_code = self.execute_command('yadtshell update')

        self.assertEqual(0, actual_return_code)

        with self.verify() as verify:
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start frontend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status frontend-service')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-host-update yit-config-it01-0:0.0.1-2')

            verify.called('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        lock_return_code = self.execute_command(
            'yadtshell unlock host://it01 -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(0, lock_return_code)

            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-host-unlock')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_return(255)
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it02.domain'))

        actual_return_code, stdout, stderr = self.execute_command_and_capture_output('yadtshell status')

        self.assertEqual(0, actual_return_code)
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('it01.domain', template=json))
            when.calling('ssh').at_least_with_arguments(
                'it01.domain').then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('it02.domain', template=json))
            when.calling('ssh').at_least_with_arguments(
                'it02.domain').then_return(0)

        status_return_code = self.execute_command('yadtshell status')
        update_return_code = self.execute_command(
            'yadtshell update host://it01 --no-final-status')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').with_input('/usr/bin/yadt-status')
            verify.called('ssh').with_input('/usr/bin/yadt-status')

            self.assertEqual(0, update_return_code)
            # status before update
            verify.called('ssh').with_input('/usr/bin/yadt-status')
            verify.called('ssh').with_input('/usr/bin/yadt-status')

            verify.called('ssh').at_least_with_arguments(
                '-O', 'check')
            verify.called('ssh').at_least_with_arguments(
                '-O', 'check')

            # prestart of it01.domain ONLY
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start service_as_json')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status service_as_json')
            # update
            verify.called('ssh').at_least_with_arguments(
                'yadt-command yadt-host-update yat-0:0.0.8 foo-0:0.0.0', 'it01.domain')
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('it02.domain'))
            when.calling('ssh').at_least_with_arguments('it02.domain') \
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', reboot_required_to_activate_latest_kernel=True))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        self.execute_command('yadtshell status')
        actual_return_code = self.execute_command('yadtshell update host://it02')

        self.assertEqual(0, actual_return_code)

        with self.verify() as verify:

            with verify.filter_by_argument('it01.domain') as filtered_verify:
                #  double status due to `status` before `update`
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain', '-O', 'check')

                filtered_verify.called('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status')

            with verify.filter_by_argument('it02.domain') as filtered_verify:
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', '-O', 'check')
                # start backend-service -> frontend service on it02
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-start backend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-status backend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-start frontend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-status frontend-service')
                filtered_verify.called('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-host-update yit-config-it02-0:0.0.1-2')
                filtered_verify.called('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status')

            verify.finished()
    def test(self):
        self.write_target_file('it01.test.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.test.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.test.domain'))

        actual_return_code = self.execute_command('yadtshell status -v')

        self.assertEqual(0, actual_return_code)

        with self.verify() as verify:
            verify.called('ssh').at_least_with_arguments(
                'it01.test.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.test.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.test.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.test.domain'))

        actual_return_code = self.execute_command('yadtshell status -v')

        self.assertEqual(0, actual_return_code)

        with self.verify() as verify:
            verify.called('ssh').at_least_with_arguments(
                'it01.test.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain', 'unreachable.host.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain').then_return(0)
            when.calling('ssh').at_least_with_arguments('unreachable.host.domain').then_return(255)

        status_return_code = self.execute_command('yadtshell status -v --ignore-unreachable-hosts')
        lock_return_code = self.execute_command(
            'yadtshell lock host://* -m "locking the hosts" -v --no-final-status')

        self.assertEqual(0, status_return_code)
        # --ignore-unreachable-hosts was not given, command must fail.
        self.assertEqual(1, lock_return_code)
    def test(self):
        self.write_target_file('it01.domain', 'unreachable.host.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain').then_return(0)
            when.calling('ssh').at_least_with_arguments('unreachable.host.domain').then_return(255)

        # "lock" command calls "status" implicitly and must pass on the
        # --ignore-unreachable-hosts option.
        lock_return_code = self.execute_command(
            'yadtshell lock host://* -m "locking the hosts" -v --no-final-status --ignore-unreachable-hosts')

        # --ignore-unreachable-hosts was not given, command must fail.
        self.assertEqual(0, lock_return_code)
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=yadt_status_answer.STATUS_JSON_TEMPLATE))

        actual_return_code = self.execute_command('yadtshell status')

        self.assertEqual(0, actual_return_code)

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            complete_verify.finished()
Esempio n. 27
0
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', reboot_required_to_activate_latest_kernel=True))
            when.calling('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status frontend-service'
            ).then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-host-update -r yit-config-it01-0:0.0.1-2'
            ).then_return(152)
            when.calling('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status backend-service'
            ).then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it01.domain').then_return(0)

        actual_return_code = self.execute_command(
            'yadtshell update -v --reboot')

        self.assertEqual(1, actual_return_code)

        with self.verify() as verify:
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-stop frontend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status frontend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-stop backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-host-update -r yit-config-it01-0:0.0.1-2')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=STATUS_TEMPLATE))
            when.calling('ssh').at_least_with_arguments('foo',
                                                        'yadt-command yadt-service-status readonly').then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain',
                                                        'yadt-command yadt-service-start service').then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain',
                                                        'yadt-command yadt-service-status service').then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain',
                                                        'yadt-command yadt-host-update yat-0:0.0.8 foo-0:0.0.0').then_return(0)

        update_return_code = self.execute_command('yadtshell update -v')

        self.assertEqual(0, update_return_code)

        with self.verify() as verify:

            # fetch full initial status + readonly information
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments('foo',
                                                         'yadt-command yadt-service-status readonly')

            # check if dependent readonly service is still running (prestart)
            verify.called('ssh').at_least_with_arguments('foo',
                                                         'yadt-command yadt-service-status readonly')

            # actual service prestart
            verify.called('ssh').at_least_with_arguments('it01.domain',
                                                         'yadt-command yadt-service-start service')
            verify.called('ssh').at_least_with_arguments('it01.domain',
                                                         'yadt-command yadt-service-status service')

            # upgrade
            verify.called('ssh').at_least_with_arguments('it01.domain',
                                                         'yadt-command yadt-host-update yat-0:0.0.8 foo-0:0.0.0')

            # fetch final status
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments('foo',
                                                         'yadt-command yadt-service-status readonly')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=yadt_status_answer.STATUS_JSON_TEMPLATE))

        actual_return_code = self.execute_command('yadtshell status')

        self.assertEqual(0, actual_return_code)

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status frontend-service').then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-host-update -r').then_return(255)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status backend-service').then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain').then_return(0)

        reboot_return_code = self.execute_command('yadtshell reboot host://it01 -v')

        self.assertEqual(0, reboot_return_code)

        with self.verify() as verify:
            # first status by yadtshell for uri expansion
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            # second status by reboot
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-stop frontend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status frontend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-stop backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-host-update -r ')

            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status backend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start frontend-service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status frontend-service')

            verify.called('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status')
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        update_return_code = self.execute_command(
            'yadtshell updateartefact artefact://*/*/// -v')  # invalid due to trailing slashes

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(1, update_return_code)
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        update_return_code = self.execute_command(
            'yadtshell updateartefact artefact://*/*/// -v'
        )  # invalid due to trailing slashes

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(1, update_return_code)
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=STATUS_JSON_TEMPLATE))
            when.calling('ssh').at_least_with_arguments('foo',
                                                        'yadt-command yadt-service-status missing_service').then_return(3)

        actual_return_code = self.execute_command('yadtshell status -v')

        self.assertEqual(0, actual_return_code)

        with self.verify() as verify:
            # fetch full initial status
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            # fetch missing read-only information
            verify.called('ssh').at_least_with_arguments('foo',
                                                         'yadt-command yadt-service-status missing_service')
    def test(self):
        self.write_target_file("it01.domain")

        with self.fixture() as when:
            when.calling("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status").then_write(
                yadt_status_answer.stdout("it01.domain", template=STATUS_TEMPLATE)
            )
            when.calling("ssh").at_least_with_arguments("foo", "yadt-command yadt-service-status readonly").then_return(
                0
            )
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-start service"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-status service"
            ).then_return(0)

        status_return_code = self.execute_command("yadtshell status")
        start_return_code = self.execute_command("yadtshell start service://it01/service -v")

        self.assertEqual(0, status_return_code)
        self.assertEqual(0, start_return_code)

        with self.verify() as verify:

            # fetch full initial status + readonly information
            verify.called("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status")
            verify.called("ssh").at_least_with_arguments("foo", "yadt-command yadt-service-status readonly")

            # check if dependent readonly service is still running
            verify.called("ssh").at_least_with_arguments("foo", "yadt-command yadt-service-status readonly")

            # ok runs, now we can start the actual service
            verify.called("ssh").at_least_with_arguments("it01.domain", "yadt-command yadt-service-start service")
            verify.called("ssh").at_least_with_arguments("it01.domain", "yadt-command yadt-service-status service")

            # fetch final status
            verify.called("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status")
            verify.called("ssh").at_least_with_arguments("foo", "yadt-command yadt-service-status readonly")
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=yadt_status_answer.STATUS_TEMPLATE_WITH_UNSATISFIABLE_DEPENDENCIES))
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status backend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        stop_return_code = self.execute_command(
            'yadtshell start service://*/backend-service -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(1, stop_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')
    def test(self):
        self.write_target_file("it01.domain")

        with self.fixture() as when:
            when.calling("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status").then_write(
                yadt_status_answer.stdout("it01.domain")
            )
            when.calling("ssh").at_least_with_arguments("it01.domain").then_return(0)

        status_return_code = self.execute_command("yadtshell status -v")
        update_return_code = self.execute_command("yadtshell updateartefact artefact://it01/yit-config-it01 -v")

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status")

            self.assertEqual(0, update_return_code)
            verify.called("ssh").at_least_with_arguments("-O", "check", "it01.domain")
            verify.called("ssh").at_least_with_arguments(
                "yadt-command yadt-artefact-update yit-config-it01", "it01.domain"
            )

            verify.called("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status")
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=STATUS_JSON_TEMPLATE))
            when.calling('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status missing_service'
            ).then_return(0)

        actual_return_code = self.execute_command('yadtshell status')

        self.assertEqual(0, actual_return_code)

        with self.verify() as verify:
            # fetch full initial status
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')
            # fetch missing read-only information
            verify.called('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status missing_service')
Esempio n. 38
0
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=yadt_status_answer.STATUS_TEMPLATE_WITH_UNSATISFIABLE_DEPENDENCIES))
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status backend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        stop_return_code = self.execute_command(
            'yadtshell start service://*/backend-service -v')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status')

            self.assertEqual(1, stop_return_code)
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check')
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_return(255)
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it02.domain'))

        actual_return_code, _, stderr = self.execute_command_and_capture_output(
            'yadtshell status --ignore-unreachable-hosts')

        self.assertEqual(0, actual_return_code)
        self.assertTrue("cannot reach host it01.domain" in stderr.lower())

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
            with complete_verify.filter_by_argument('it02.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_return(255)
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it02.domain'))

        actual_return_code, _, stderr = self.execute_command_and_capture_output(
            'yadtshell status --ignore-unreachable-hosts')

        self.assertEqual(0, actual_return_code)
        self.assertTrue("cannot reach host it01.domain" in stderr.lower())

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
            with complete_verify.filter_by_argument('it02.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=yadt_status_answer.STATUS_JSON_TEMPLATE))

        actual_return_code = self.execute_command('yadtshell status')
        self.assertEqual(0, actual_return_code)

        self.assertEqual(
            0,
            self.execute_command(
                'yadtshell info | grep " u " | grep "host uptodate"'))
        return_code, stdout, _ = self.execute_command_and_capture_output(
            'yadtshell info')
        update_found_for_foo = False
        for line in stdout.splitlines():
            if re.search('\(next\) foo', line):
                update_found_for_foo = True
                break
        self.assertTrue(
            update_found_for_foo,
            'yit not obsoleted by foo, info was:{0}'.format(stdout))

        self.assertEqual(
            0,
            self.execute_command(
                'yadtshell dump --show-pending-updates | grep foo'))

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            complete_verify.finished()
Esempio n. 42
0
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments(
                'it01.domain').and_input('/usr/bin/yadt-status').then_write(
                    yadt_status_answer.stdout('it01.domain',
                                              template=template_it01_domain))
            when.calling('ssh').at_least_with_arguments(
                'it01.domain').then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it02.domain').and_input('/usr/bin/yadt-status').then_write(
                    yadt_status_answer.stdout('it02.domain',
                                              template=template_it02_domain))
            when.calling('ssh').at_least_with_arguments(
                'it02.domain').then_return(0)

        status_return_code = self.execute_command('yadtshell status')
        update_return_code = self.execute_command(
            'yadtshell update host://it01 --no-final-status')

        with self.verify() as verify:
            self.assertEqual(0, status_return_code)
            verify.called('ssh').with_input('/usr/bin/yadt-status')
            verify.called('ssh').with_input('/usr/bin/yadt-status')

            self.assertEqual(0, update_return_code)
            # status before update
            verify.called('ssh').with_input('/usr/bin/yadt-status')
            verify.called('ssh').with_input('/usr/bin/yadt-status')

            verify.called('ssh').at_least_with_arguments('-O', 'check')
            verify.called('ssh').at_least_with_arguments('-O', 'check')

            # prestart of it01.domain services w/o dependencies
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start bar_service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status bar_service')

            # prestart of it02.domain services that are needed
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-start ham_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-status ham_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-start spam_service')
            verify.called('ssh').at_least_with_arguments(
                'it02.domain', 'yadt-command yadt-service-status spam_service')

            # prestart of the it01.domain service that had the it02 dependency
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-start foo_service')
            verify.called('ssh').at_least_with_arguments(
                'it01.domain', 'yadt-command yadt-service-status foo_service')

            # the eggs_service has NOT been started

            # update
            verify.called('ssh').at_least_with_arguments(
                'yadt-command yadt-host-update yat-0:0.0.8 foo-0:0.0.0',
                'it01.domain')
    def test(self):
        self.write_target_file('it01.domain it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it02.domain'))

            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-stop frontend-service') \
                .then_return(0, milliseconds_to_wait=0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status frontend-service')\
                .then_return(1)

            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-stop frontend-service') \
                .then_return(0, milliseconds_to_wait=0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status frontend-service')\
                .then_return(1)

        status_return_code = self.execute_command('yadtshell status -v')

        if (parallel):
            chunks = [
                Chunk("chunk1", self.execute_command,
                      'yadtshell stop service://it01/frontend-service -v'),
                Chunk("chunk2", self.execute_command,
                      'yadtshell stop service://it02/frontend-service -v')
            ]
            [chunk.start() for chunk in chunks]
            [chunk.join(20) for chunk in chunks]
            for chunk in chunks:
                if chunk.isAlive():
                    print("%s timed out!" % chunk.chunkId)
                else:
                    print("%s returned %s" % (chunk.chunkId, chunk.exitcode))
            stop1_return_code = chunks[0].exitcode
            stop2_return_code = chunks[1].exitcode
        else:
            stop1_return_code = self.execute_command(
                'yadtshell stop service://it01/frontend-service -v')
            stop2_return_code = self.execute_command(
                'yadtshell stop service://it02/frontend-service -v')

        with self.verify() as complete_verify:
            self.assertEqual(0, status_return_code)
            self.assertEqual(0, stop1_return_code)
            self.assertEqual(0, stop2_return_code)

            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            with complete_verify.filter_by_argument('it02.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')

            complete_verify.finished()
    def test(self):
        self.write_target_file("it01.domain", "it02.domain")

        with self.fixture() as when:
            when.calling("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status").then_write(
                yadt_status_answer.stdout("it01.domain")
            )
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-status frontend-service"
            ).then_return(3).then_return(0)
            when.calling("ssh").at_least_with_arguments("it01.domain", "yadt-command yadt-host-update -r").then_return(
                255
            )
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-status backend-service"
            ).then_return(3).then_return(0)
            when.calling("ssh").at_least_with_arguments("it01.domain").then_return(0)
            when.calling("ssh").at_least_with_arguments("it02.domain").and_input("/usr/bin/yadt-status").then_write(
                yadt_status_answer.stdout("it02.domain")
            )
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-service-status frontend-service"
            ).then_return(3).then_return(0)
            when.calling("ssh").at_least_with_arguments("it02.domain", "yadt-command yadt-host-update -r").then_return(
                255
            )
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-service-status backend-service"
            ).then_return(3).then_return(0)
            when.calling("ssh").at_least_with_arguments("it02.domain").then_return(0)

        reboot_return_code = self.execute_command("yadtshell reboot host://* -v")

        self.assertEqual(0, reboot_return_code)

        with self.verify() as outer_verify:
            with outer_verify.filter_by_argument("it01.domain") as verify:
                verify.called("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status")
                verify.called("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status")
                verify.called("ssh").at_least_with_arguments("it01.domain", "-O", "check")
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-stop frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-status frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-stop backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-status backend-service"
                )
                verify.called("ssh").at_least_with_arguments("it01.domain", "yadt-command yadt-host-update -r ")
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-start backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-status backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-start frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-status frontend-service"
                )
                verify.called("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status")

            with outer_verify.filter_by_argument("it02.domain") as verify:
                verify.called("ssh").at_least_with_arguments("it02.domain").and_input("/usr/bin/yadt-status")
                verify.called("ssh").at_least_with_arguments("it02.domain").and_input("/usr/bin/yadt-status")
                verify.called("ssh").at_least_with_arguments("it02.domain", "-O", "check")
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-stop frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-status frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-stop backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-status backend-service"
                )
                verify.called("ssh").at_least_with_arguments("it02.domain", "yadt-command yadt-host-update -r ")
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-start backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-status backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-start frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-status frontend-service"
                )
                verify.called("ssh").at_least_with_arguments("it02.domain").and_input("/usr/bin/yadt-status")

            outer_verify.finished()
    def test(self):
        self.write_target_file("it01.domain", "it02.domain")

        with self.fixture() as when:
            when.calling("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status").then_write(
                yadt_status_answer.stdout(
                    "it01.domain", template=yadt_status_answer.STATUS_TEMPLATE_WITH_ARTIFACT_SERVICE_DEPENDENCIES
                )
            )
            when.calling("ssh").at_least_with_arguments("it01.domain", "-O", "check").then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-stop frontend-service"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-status frontend-service"
            ).then_return(3).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-stop backend-service"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-status backend-service"
            ).then_return(3).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-host-update yit-config-it01-0:0.0.1-2"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments("it01.domain", "yadt-command yadt-host-status").then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-start backend-service"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it01.domain", "yadt-command yadt-service-start frontend-service"
            ).then_return(0)

            when.calling("ssh").at_least_with_arguments("it02.domain").and_input("/usr/bin/yadt-status").then_write(
                yadt_status_answer.stdout(
                    "it02.domain", template=yadt_status_answer.STATUS_TEMPLATE_WITH_ARTIFACT_SERVICE_DEPENDENCIES
                )
            )
            when.calling("ssh").at_least_with_arguments("it02.domain", "-O", "check").then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-service-stop frontend-service"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-service-status frontend-service"
            ).then_return(3).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-service-stop backend-service"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-service-status backend-service"
            ).then_return(3).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-host-update yit-config-it02-0:0.0.1-2"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments("it02.domain", "yadt-command yadt-host-status").then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-service-start backend-service"
            ).then_return(0)
            when.calling("ssh").at_least_with_arguments(
                "it02.domain", "yadt-command yadt-service-start frontend-service"
            ).then_return(0)

        actual_return_code = self.execute_command("yadtshell update -v -p 99")

        self.assertEqual(0, actual_return_code)

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument("it01.domain") as verify:
                verify.called("ssh").at_least_with_arguments("it01.domain")
                verify.called("ssh").at_least_with_arguments("it01.domain", "-O", "check")
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-stop frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-status frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-stop backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-status backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-host-update yit-config-it01-0:0.0.1-2"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-start backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-status backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-start frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it01.domain", "yadt-command yadt-service-status frontend-service"
                )
                verify.called("ssh").at_least_with_arguments("it01.domain").and_input("/usr/bin/yadt-status")

            with complete_verify.filter_by_argument("it02.domain") as verify:
                verify.called("ssh").at_least_with_arguments("it02.domain")
                verify.called("ssh").at_least_with_arguments("it02.domain", "-O", "check")
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-stop frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-status frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-stop backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-status backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-host-update yit-config-it02-0:0.0.1-2"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-start backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-status backend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-start frontend-service"
                )
                verify.called("ssh").at_least_with_arguments(
                    "it02.domain", "yadt-command yadt-service-status frontend-service"
                )
                verify.called("ssh").at_least_with_arguments("it02.domain")

            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it02.domain'))

            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-stop frontend-service') \
                .then_return(0, milliseconds_to_wait=0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status frontend-service')\
                .then_return(1)

            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-stop frontend-service') \
                .then_return(0, milliseconds_to_wait=0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status frontend-service')\
                .then_return(1)

        status_return_code = self.execute_command('yadtshell status -v')

        if (parallel):
            chunks = [
                Chunk("chunk1", self.execute_command,
                      'yadtshell stop service://it01/frontend-service -v'),
                Chunk("chunk2", self.execute_command,
                      'yadtshell stop service://it02/frontend-service -v')
            ]
            [chunk.start() for chunk in chunks]
            [chunk.join(20) for chunk in chunks]
            for chunk in chunks:
                if chunk.isAlive():
                    print("%s timed out!" % chunk.chunkId)
                else:
                    print("%s returned %s" % (chunk.chunkId, chunk.exitcode))
            stop1_return_code = chunks[0].exitcode
            stop2_return_code = chunks[1].exitcode
        else:
            stop1_return_code = self.execute_command(
                'yadtshell stop service://it01/frontend-service -v')
            stop2_return_code = self.execute_command(
                'yadtshell stop service://it02/frontend-service -v')

        with self.verify() as complete_verify:
            self.assertEqual(0, status_return_code)
            self.assertEqual(0, stop1_return_code)
            self.assertEqual(0, stop2_return_code)

            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            with complete_verify.filter_by_argument('it02.domain') as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')

            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status frontend-service'
            ).then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-host-update -r').then_return(255)
            when.calling('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-service-status backend-service'
            ).then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it01.domain').then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it02.domain'))
            when.calling('ssh').at_least_with_arguments(
                'it02.domain',
                'yadt-command yadt-service-status frontend-service'
            ).then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it02.domain',
                'yadt-command yadt-host-update -r').then_return(255)
            when.calling('ssh').at_least_with_arguments(
                'it02.domain',
                'yadt-command yadt-service-status backend-service'
            ).then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it02.domain').then_return(0)

        reboot_return_code = self.execute_command(
            'yadtshell reboot host://* -v')

        self.assertEqual(0, reboot_return_code)

        with self.verify() as outer_verify:
            with outer_verify.filter_by_argument("it01.domain") as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', '-O', 'check')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-stop backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-host-update -r ')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-start backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-start frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            with outer_verify.filter_by_argument("it02.domain") as verify:
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', '-O', 'check')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-stop backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-host-update -r ')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-start backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-start frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')

            outer_verify.finished()
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain', template=yadt_status_answer.STATUS_TEMPLATE_WITH_ARTIFACT_SERVICE_DEPENDENCIES))
            when.calling('ssh').at_least_with_arguments(
                'it01.domain', '-O', 'check').then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-stop frontend-service')\
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status frontend-service') \
                .then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-stop backend-service') \
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status backend-service') \
                .then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it01.domain',
                'yadt-command yadt-host-update yit-config-it01-0:0.0.1-2'
            ).then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-host-status')\
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-start backend-service') \
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-start frontend-service') \
                .then_return(0)

            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it02.domain', template=yadt_status_answer.STATUS_TEMPLATE_WITH_ARTIFACT_SERVICE_DEPENDENCIES))
            when.calling('ssh').at_least_with_arguments(
                'it02.domain', '-O', 'check').then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-stop frontend-service') \
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status frontend-service') \
                .then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-stop backend-service') \
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status backend-service') \
                .then_return(3).then_return(0)
            when.calling('ssh').at_least_with_arguments(
                'it02.domain',
                'yadt-command yadt-host-update yit-config-it02-0:0.0.1-2'
            ).then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-host-status') \
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-start backend-service') \
                .then_return(0)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-start frontend-service') \
                .then_return(0)

        actual_return_code = self.execute_command('yadtshell update -v -p 99')

        self.assertEqual(0, actual_return_code)

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_with_arguments('it01.domain')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', '-O', 'check')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-stop backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-host-update yit-config-it01-0:0.0.1-2')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-start backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-start frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            with complete_verify.filter_by_argument('it02.domain') as verify:
                verify.called('ssh').at_least_with_arguments('it02.domain')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', '-O', 'check')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-stop backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-host-update yit-config-it02-0:0.0.1-2')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-start backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-start frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments('it02.domain')

            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain', 'it03.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

            when.calling('ssh').at_least_with_arguments('it02.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it02.domain'))
            when.calling('ssh').at_least_with_arguments('it02.domain') \
                .then_return(0)

            when.calling('ssh').at_least_with_arguments('it03.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it03.domain'))
            when.calling('ssh').at_least_with_arguments('it03.domain') \
                .then_return(0)

        actual_return_code = self.execute_command('yadtshell update -v -p 99')

        self.assertEqual(0, actual_return_code)

        with self.verify() as complete_verify:
            with complete_verify.filter_by_argument('it01.domain') as filtered_verify:
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain', '-O', 'check')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-start backend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-status backend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-start frontend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-status frontend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-host-update yit-config-it01-0:0.0.1-2')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            with complete_verify.filter_by_argument('it02.domain') as filtered_verify:
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', '-O', 'check')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-start backend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-status backend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-start frontend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-status frontend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-host-update yit-config-it02-0:0.0.1-2')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it02.domain').and_input('/usr/bin/yadt-status')

            with complete_verify.filter_by_argument('it03.domain') as filtered_verify:
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it03.domain').and_input('/usr/bin/yadt-status')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it03.domain', '-O', 'check')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it03.domain', 'yadt-command yadt-service-start backend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it03.domain', 'yadt-command yadt-service-status backend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it03.domain', 'yadt-command yadt-service-start frontend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it03.domain', 'yadt-command yadt-service-status frontend-service')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it03.domain', 'yadt-command yadt-host-update yit-config-it03-0:0.0.1-2')
                filtered_verify.called('ssh').at_least_with_arguments(
                    'it03.domain').and_input('/usr/bin/yadt-status')

            complete_verify.finished()
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status frontend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status backend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

            when.calling('ssh').at_least_with_arguments('it02.domain').and_input(
                '/usr/bin/yadt-status').then_write(yadt_status_answer.stdout('it02.domain'))
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status frontend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status backend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it02.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        stop_return_code = self.execute_command(
            'yadtshell stop service://* -v -p 2')

        with self.verify() as complete_verifier:
            self.assertEqual(0, status_return_code)
            self.assertEqual(0, stop_return_code)

            with complete_verifier.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_one_argument_matches(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', '-O', 'check')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-stop backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', 'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_one_argument_matches(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            with complete_verifier.filter_by_argument('it02.domain') as verify:
                verify.called('ssh').at_least_one_argument_matches(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', '-O', 'check')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-stop backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', 'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_one_argument_matches(
                    'it02.domain').and_input('/usr/bin/yadt-status')

            complete_verifier.finished()
Esempio n. 51
0
    def test(self):
        self.write_target_file('it01.domain', 'it02.domain')

        with self.fixture() as when:
            when.calling('ssh').at_least_with_arguments('it01.domain').and_input('/usr/bin/yadt-status') \
                .then_write(yadt_status_answer.stdout('it01.domain'))
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status frontend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it01.domain', 'yadt-command yadt-service-status backend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it01.domain') \
                .then_return(0)

            when.calling('ssh').at_least_with_arguments(
                'it02.domain').and_input('/usr/bin/yadt-status').then_write(
                    yadt_status_answer.stdout('it02.domain'))
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status frontend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it02.domain', 'yadt-command yadt-service-status backend-service')\
                .then_return(1)
            when.calling('ssh').at_least_with_arguments('it02.domain') \
                .then_return(0)

        status_return_code = self.execute_command('yadtshell status -v')
        stop_return_code = self.execute_command(
            'yadtshell stop service://* -v -p 2')

        with self.verify() as complete_verifier:
            self.assertEqual(0, status_return_code)
            self.assertEqual(0, stop_return_code)

            with complete_verifier.filter_by_argument('it01.domain') as verify:
                verify.called('ssh').at_least_one_argument_matches(
                    'it01.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain', '-O', 'check')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-stop backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it01.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_one_argument_matches(
                    'it01.domain').and_input('/usr/bin/yadt-status')

            with complete_verifier.filter_by_argument('it02.domain') as verify:
                verify.called('ssh').at_least_one_argument_matches(
                    'it02.domain').and_input('/usr/bin/yadt-status')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain', '-O', 'check')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-stop frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status frontend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-stop backend-service')
                verify.called('ssh').at_least_with_arguments(
                    'it02.domain',
                    'yadt-command yadt-service-status backend-service')
                verify.called('ssh').at_least_one_argument_matches(
                    'it02.domain').and_input('/usr/bin/yadt-status')

            complete_verifier.finished()