blob: 3851e8d058d8ec6087e1141896464a99308abf7a [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
Hanna Arhipovaa85bfa62020-01-03 18:49:15 +020041 def start_job_on_jenkins(
42 self,
43 job_name,
44 jenkins_tgt='I@docker:client:stack:jenkins and cid01*',
45 **kwargs):
Hanna Arhipova17b2c102019-09-06 16:44:17 +030046 """
47 Starts job with specific parameters on cluster Jenkins
48
49 Method accept any param:
50 job_parameters=None,
51 job_output_prefix='',
52 start_timeout=1800,
53 build_timeout=3600 * 4,
54 verbose=False
55
56 :param job_name: string
57 :return: string, Result of passed job, "SUCCESS"| "FAILED" | "UNSTABLE"
58 """
59 jenkins_url, jenkins_user, jenkins_pass = self.get_jenkins_creds(
Hanna Arhipovaa85bfa62020-01-03 18:49:15 +020060 tgt=jenkins_tgt)
Hanna Arhipova17b2c102019-09-06 16:44:17 +030061
62 job_result = run_jenkins_job.run_job(
63 host=jenkins_url,
64 username=jenkins_user,
65 password=jenkins_pass,
66 job_name=job_name,
67 **kwargs)
68
69 (description, stages) = get_jenkins_job_stages.get_deployment_result(
70 host=jenkins_url,
71 username=jenkins_user,
72 password=jenkins_pass,
73 job_name=job_name,
74 build_number='lastBuild')
75
76 LOG.info(description)
77 LOG.info('\n'.join(stages))
78
79 if job_result != 'SUCCESS':
80 LOG.warning("{0}\n{1}".format(description, '\n'.join(stages)))
81 return job_result
82
83 def start_job_on_cfg_jenkins(self):
84 pass
85
86 def get_jenkins_creds(self, tgt):
87 """
88 Requests Jenkins's login parameters from pillars from desired node
89
90 :return: tuple {jenkins_url, jenkins_user, jenkins_pass}
91 """
92 jenkins_host = self._salt.get_single_pillar(
93 tgt=tgt, pillar="jenkins:client:master:host")
94 if jenkins_host is None:
95 raise Exception(
96 "Can't find 'jenkins:client:master' pillar on {tgt} node."
97 .format(tgt=tgt))
98 jenkins_port = self._salt.get_single_pillar(
99 tgt=tgt, pillar="jenkins:client:master:port")
100 jenkins_protocol = self._salt.get_single_pillar(
101 tgt=tgt, pillar="jenkins:client:master:proto")
102 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
103 jenkins_host,
104 jenkins_port)
105 jenkins_user = self._salt.get_single_pillar(
106 tgt=tgt, pillar="jenkins:client:master:username")
107 jenkins_pass = self._salt.get_single_pillar(
108 tgt=tgt, pillar="jenkins:client:master:password")
109 return jenkins_url, jenkins_user, jenkins_pass