Example #1
0
    def _get_api(self, api_ver):
        try:
            api_v3 = []
            api_v4 = []

            def get():
                instance = self._create_api(api_ver)
                if instance:
                    if api_ver == 3:
                        api_v3.append(instance)
                    else:
                        api_v4.append(instance)
                    return True
                return False

            testlib.assert_true_within_short(
                get,
                allowed_exceptions=[RequestError, ConnectionError],
            )
        except AssertionError:
            raise RuntimeError('Failed to connect to the engine')
        if api_ver == 3:
            return api_v3.pop()
        else:
            testapi = api_v4.pop()
            counter = 1
            while not testapi.test():
                if counter == 20:
                    raise RuntimeError('test api call failed')
                else:
                    time.sleep(3)
                    counter += 1

            return testapi
Example #2
0
    def _get_api(self, api_ver):
        try:
            api_v3 = []
            api_v4 = []

            def get():
                instance = self._create_api(api_ver)
                if instance:
                    if api_ver == 3:
                        api_v3.append(instance)
                    else:
                        api_v4.append(instance)
                    return True
                return False

            testlib.assert_true_within_short(
                get,
                allowed_exceptions=[RequestError, ConnectionError],
            )
        except AssertionError:
            raise RuntimeError('Failed to connect to the engine')

        if api_ver == 3:
            return api_v3.pop()
        else:
            testapi = api_v4.pop()
            counter = 1
            while not testapi.test():
                if counter == 20:
                    raise RuntimeError('test api call failed')
                else:
                    time.sleep(3)
                    counter += 1

            return testapi
Example #3
0
    def test_add_slaves(self, jenkins_api, prefix, cred_uuid):
        def add_slave(hostname, label):
            if jenkins_api.node_exists(hostname):
                return True

            params = {
                'port': '22',
                'username': '******',
                'host': hostname,
                'credentialsId': cred_uuid,
            }

            jenkins_api.create_node(hostname,
                                    nodeDescription='test slave',
                                    labels=label,
                                    numExecutors=1,
                                    exclusive=True,
                                    launcher=jenkins.LAUNCHER_SSH,
                                    launcher_params=params)

            return True

        slaves_and_labels = [(vm.name(), vm.metadata.get('jenkins-label'))
                             for vm in prefix.get_vms().viewvalues()
                             if 'jenkins-slaves' in vm.groups]

        vec = lago.utils.func_vector(add_slave, slaves_and_labels)
        vt = lago.utils.VectorThread(vec)
        vt.start_all()
        assert all(vt.join_all())

        for slave, _ in slaves_and_labels:
            print jenkins_api.get_node_info(slave)
            testlib.assert_true_within_short(
                functools.partial(jenkins_api.node_exists, slave))
Example #4
0
def _activate_all_hosts(api):
    names = [host.name for host in api.hosts.list()]

    for name in names:
        try:
            api.hosts.get(name).activate()
        except RequestError:
            pass

    for name in names:
        testlib.assert_true_within_short(
            lambda: api.hosts.get(name).status.state == 'up',
        )
def _activate_all_hosts(api):
    names = [host.name for host in api.hosts.list()]

    for name in names:
        try:
            api.hosts.get(name).activate()
        except RequestError:
            pass

    for name in names:
        testlib.assert_true_within_short(
            lambda: api.hosts.get(name).status.state == 'up',
        )
Example #6
0
    def _get_api(self, wait):
        if wait:
            self.wait_for_ssh()
            try:
                testlib.assert_true_within_long(
                    lambda: self.service('ovirt-engine').alive())

                api = []
                testlib.assert_true_within_short(
                    lambda: api.append(self._create_api()) or True)
            except AssertionError:
                raise RuntimeError('Failed to connect to the engine')
        return api.pop()
Example #7
0
    def test_basic_api_connection(self, jenkins_api):
        def _test_api():
            user = jenkins_api.get_whoami()
            version = jenkins_api.get_version()
            print('Hello {} from Jenkins {}'.format(user['fullName'], version))

            return True

        testlib.assert_true_within_short(_test_api,
                                         allowed_exceptions=[
                                             jenkins.BadHTTPException,
                                             jenkins.JenkinsException,
                                             jenkins.TimeoutException
                                         ])
Example #8
0
    def _get_api(self, wait):
        if wait:
            self.wait_for_ssh()
            try:
                testlib.assert_true_within_long(
                    lambda: self.service('ovirt-engine').alive()
                )

                api = []
                testlib.assert_true_within_short(
                    lambda: api.append(self._create_api()) or True
                )
            except AssertionError:
                raise RuntimeError('Failed to connect to the engine')
        return api.pop()
def _deactivate_all_hosts(api):
    hosts = api.hosts.list()

    while hosts:
        host = hosts.pop()
        try:
            host.deactivate()
            logging.info('Sent host %s to maintenance', host.name)
        except RequestError:
            logging.exception('Failed to maintenance host %s', host.name)
            hosts.insert(0, host)

    for host in api.hosts.list():
        logging.debug('Waiting for %s to go into maintenance', host.name)
        testlib.assert_true_within_short(
            lambda: api.hosts.get(host.name).status.state == 'maintenance',
        )
    def test_add_slaves(self, jenkins_api, env, cred_uuid):
        def add_slave(hostname, label):
            if jenkins_api.node_exists(hostname):
                return True

            params = {
                'port': '22',
                'username': '******',
                'host': hostname,
                'credentialsId': cred_uuid,
            }

            jenkins_api.create_node(
                hostname,
                nodeDescription='test slave',
                labels=label,
                numExecutors=1,
                exclusive=True,
                launcher=jenkins.LAUNCHER_SSH,
                launcher_params=params
            )

            return True

        # Task: Create a list of tuples where each tuple contains
        # a vm name and it's jenkins label, for example (vm-0, dev)
        # Recall that only vms in group 'jenkins-slaves' has a label
        raise NotImplementedError('Implement me')
        slaves_and_labels = []
        # EndTask

        vec = lago.utils.func_vector(add_slave, slaves_and_labels)
        vt = lago.utils.VectorThread(vec)
        vt.start_all()
        assert all(vt.join_all())

        for slave, _ in slaves_and_labels:
            testlib.assert_true_within_short(
                functools.partial(jenkins_api.node_exists, slave)
            )
            testlib.assert_true_within_short(
                lambda: not jenkins_api.get_node_info(slave)['offline']
            )
Example #11
0
def _deactivate_all_hosts(api):
    hosts = api.hosts.list()

    while hosts:
        host = hosts.pop()
        try:
            host.deactivate()
            LOGGER.info('Sent host %s to maintenance', host.name)
        except RequestError:
            LOGGER.exception('Failed to maintenance host %s', host.name)
            hosts.insert(0, host)

    for host in api.hosts.list():
        with LogTask(
            'Wait for %s to go into maintenance' % host.name,
            level='debug',
        ):
            testlib.assert_true_within_short(
                lambda: api.hosts.get(host.name).status.state == 'maintenance',
            )
Example #12
0
    def test_basic_api_connection(self, jenkins_api, jenkins_master,
                                  jenkins_info):
        def _test_api():
            user = jenkins_api.get_whoami()
            version = jenkins_api.get_version()
            print('Hello {} from Jenkins {}'.format(user['fullName'], version))
            print('You can access the web UI with:\nhttp://{}:{}'.format(
                jenkins_master.ip(), jenkins_info['port']))

            return True

        allowed_exceptions = [
            jenkins.BadHTTPException, jenkins.JenkinsException,
            jenkins.TimeoutException
        ]

        # Task: assert _test_api ends successfully within a short timeout
        # allowing 'allowed_exceptions'
        testlib.assert_true_within_short(_test_api,
                                         allowed_exceptions=allowed_exceptions)
Example #13
0
    def test_trigger_labeled_job(self, jenkins_api, prefix):
        labeled_nodes = [
            vm.name() for vm in prefix.get_vms().viewvalues()
            if vm.metadata.get('jenkins-label') == DEV_LABEL
        ]
        dev_job_info = jenkins_api.get_job_info(DEV_JOB)
        next_build_number = dev_job_info['nextBuildNumber']
        jenkins_api.build_job(DEV_JOB)

        def has_running_build():
            running_builds = jenkins_api.get_running_builds()
            return len(running_builds) == 0

        def assert_job_run_on_labeled_slave(job, build_number,
                                            optional_slaves):
            build_info = jenkins_api.get_build_info(job, build_number)
            assert build_info['builtOn'] in optional_slaves

        testlib.assert_true_within_short(has_running_build)

        testlib.allow_exceptions_within_short(
            functools.partial(assert_job_run_on_labeled_slave, DEV_JOB,
                              next_build_number, labeled_nodes),
            [jenkins.NotFoundException])