Revision 6868804a ci/utils.py
b/ci/utils.py | ||
---|---|---|
36 | 36 |
return fabric.run(cmd) |
37 | 37 |
|
38 | 38 |
|
39 |
def _put(local, remote): |
|
40 |
"""Run fabric put command without output""" |
|
41 |
with fabric.quiet(): |
|
42 |
fabric.put(local, remote) |
|
43 |
|
|
44 |
|
|
39 | 45 |
def _red(msg): |
40 | 46 |
"""Red color""" |
41 | 47 |
#return "\x1b[31m" + str(msg) + "\x1b[0m" |
... | ... | |
226 | 232 |
self._wait_transition(server_id, "ACTIVE", "DELETED") |
227 | 233 |
|
228 | 234 |
@_check_kamaki |
229 |
def create_server(self, image_id=None, flavor_id=None): |
|
235 |
def create_server(self, image_id=None, flavor_id=None, ssh_keys=None):
|
|
230 | 236 |
"""Create slave server""" |
231 | 237 |
self.logger.info("Create a new server..") |
232 | 238 |
if image_id is None: |
... | ... | |
251 | 257 |
|
252 | 258 |
server = self._wait_transition(server_id, "BUILD", "ACTIVE") |
253 | 259 |
self._get_server_ip_and_port(server) |
254 |
self._copy_ssh_keys() |
|
260 |
self._copy_ssh_keys(ssh_keys)
|
|
255 | 261 |
|
256 | 262 |
self.setup_fabric() |
257 | 263 |
self.logger.info("Setup firewall") |
258 |
accept_ssh_from = self.config.get('Global', 'filter_access_network')
|
|
264 |
accept_ssh_from = self.config.get('Global', 'accept_ssh_from')
|
|
259 | 265 |
if accept_ssh_from != "": |
260 | 266 |
self.logger.debug("Block ssh except from %s" % accept_ssh_from) |
261 | 267 |
cmd = """ |
... | ... | |
300 | 306 |
self.logger.debug("Server's IPv4 is %s" % _green(server_ip)) |
301 | 307 |
self.write_config('server_port', server_port) |
302 | 308 |
self.logger.debug("Server's ssh port is %s" % _green(server_port)) |
309 |
self.logger.debug("Access server using \"ssh -p %s %s@%s\"" % |
|
310 |
(server_port, fabric.env.user, server_ip)) |
|
303 | 311 |
|
304 | 312 |
@_check_fabric |
305 |
def _copy_ssh_keys(self): |
|
313 |
def _copy_ssh_keys(self, ssh_keys):
|
|
306 | 314 |
"""Upload/Install ssh keys to server""" |
307 |
if not self.config.has_option("Deployment", "ssh_keys"):
|
|
308 |
return
|
|
309 |
authorized_keys = self.config.get("Deployment",
|
|
310 |
"ssh_keys") |
|
311 |
if authorized_keys != "" and os.path.exists(authorized_keys):
|
|
315 |
self.logger.debug("Check for authentication keys to upload")
|
|
316 |
if ssh_keys is None:
|
|
317 |
ssh_keys = self.config.get("Deployment", "ssh_keys")
|
|
318 |
|
|
319 |
if ssh_keys != "" and os.path.exists(ssh_keys):
|
|
312 | 320 |
keyfile = '/tmp/%s.pub' % fabric.env.user |
313 | 321 |
_run('mkdir -p ~/.ssh && chmod 700 ~/.ssh', False) |
314 |
fabric.put(authorized_keys, keyfile)
|
|
322 |
_put(ssh_keys, keyfile)
|
|
315 | 323 |
_run('cat %s >> ~/.ssh/authorized_keys' % keyfile, False) |
316 | 324 |
_run('rm %s' % keyfile, False) |
317 | 325 |
self.logger.debug("Uploaded ssh authorized keys") |
... | ... | |
506 | 514 |
raise ValueError("Unknown schema: %s" % schema) |
507 | 515 |
|
508 | 516 |
self.logger.debug("Upload schema files to server") |
509 |
with fabric.quiet(): |
|
510 |
fabric.put(os.path.join(schema_dir, "*"), "/etc/snf-deploy/") |
|
517 |
_put(os.path.join(schema_dir, "*"), "/etc/snf-deploy/") |
|
511 | 518 |
|
512 | 519 |
self.logger.debug("Change password in nodes.conf file") |
513 | 520 |
cmd = """ |
... | ... | |
536 | 543 |
|
537 | 544 |
self.logger.debug("Upload tests.sh file") |
538 | 545 |
unit_tests_file = os.path.join(self.ci_dir, "tests.sh") |
539 |
with fabric.quiet(): |
|
540 |
fabric.put(unit_tests_file, ".") |
|
546 |
_put(unit_tests_file, ".") |
|
541 | 547 |
|
542 | 548 |
self.logger.debug("Run unit tests") |
543 | 549 |
cmd = """ |
Also available in: Unified diff