blob: 8ef758da42f973d35d19acf403b5ac030ce23de4 [file] [log] [blame]
sgudzb67ce732018-02-13 17:58:31 +02001# Copyright 2017 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
Hanna Arhipova17b2c102019-09-06 16:44:17 +030016from tcp_tests.utils import run_jenkins_job
17from tcp_tests.utils import get_jenkins_job_stages
18from tcp_tests import logger
19
20LOG = logger.logger
sgudzb67ce732018-02-13 17:58:31 +020021
22
23class DrivetrainManager(ExecuteCommandsMixin):
24 """docstring for DrivetrainManager"""
25
26 __config = None
27 __underlay = None
28
29 def __init__(self, config, underlay, salt=None):
30 self.__config = config
31 self.__underlay = underlay
32 self._salt = salt
33 super(DrivetrainManager, self).__init__(
34 config=config, underlay=underlay)
35
36 def install(self, commands):
37 self.execute_commands(commands,
38 label='Install Drivetrain Tools')
39 self.__config.drivetrain.drivetrain_installed = True
Hanna Arhipova17b2c102019-09-06 16:44:17 +030040
41 def start_job_on_cid_jenkins(self, job_name,
42 **kwargs):
43 """
44 Starts job with specific parameters on cluster Jenkins
45
46 Method accept any param:
47 job_parameters=None,
48 job_output_prefix='',
49 start_timeout=1800,
50 build_timeout=3600 * 4,
51 verbose=False
52
53 :param job_name: string
54 :return: string, Result of passed job, "SUCCESS"| "FAILED" | "UNSTABLE"
55 """
56 jenkins_url, jenkins_user, jenkins_pass = self.get_jenkins_creds(
57 tgt='I@docker:client:stack:jenkins and cid01*')
58
59 job_result = run_jenkins_job.run_job(
60 host=jenkins_url,
61 username=jenkins_user,
62 password=jenkins_pass,
63 job_name=job_name,
64 **kwargs)
65
66 (description, stages) = get_jenkins_job_stages.get_deployment_result(
67 host=jenkins_url,
68 username=jenkins_user,
69 password=jenkins_pass,
70 job_name=job_name,
71 build_number='lastBuild')
72
73 LOG.info(description)
74 LOG.info('\n'.join(stages))
75
76 if job_result != 'SUCCESS':
77 LOG.warning("{0}\n{1}".format(description, '\n'.join(stages)))
78 return job_result
79
80 def start_job_on_cfg_jenkins(self):
81 pass
82
83 def get_jenkins_creds(self, tgt):
84 """
85 Requests Jenkins's login parameters from pillars from desired node
86
87 :return: tuple {jenkins_url, jenkins_user, jenkins_pass}
88 """
89 jenkins_host = self._salt.get_single_pillar(
90 tgt=tgt, pillar="jenkins:client:master:host")
91 if jenkins_host is None:
92 raise Exception(
93 "Can't find 'jenkins:client:master' pillar on {tgt} node."
94 .format(tgt=tgt))
95 jenkins_port = self._salt.get_single_pillar(
96 tgt=tgt, pillar="jenkins:client:master:port")
97 jenkins_protocol = self._salt.get_single_pillar(
98 tgt=tgt, pillar="jenkins:client:master:proto")
99 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
100 jenkins_host,
101 jenkins_port)
102 jenkins_user = self._salt.get_single_pillar(
103 tgt=tgt, pillar="jenkins:client:master:username")
104 jenkins_pass = self._salt.get_single_pillar(
105 tgt=tgt, pillar="jenkins:client:master:password")
106 return jenkins_url, jenkins_user, jenkins_pass