Commit 8403213f authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed error with environment. It need the json not the name

parent 9b72148c
......@@ -79,11 +79,11 @@ class SemaphoreHelper:
return self.find_template(templates,playbook_name).id
def execute_task(self, project_id, template_id, playbook_name,environment_id=None):
environment_name = None
environment_json = None
if environment_id:
environment = self.find_environment(project_id,environment_id=environment_id)
environment_name = environment.name
task = Task(template_id=template_id, playbook=playbook_name,environment=environment_name)
environment_json = environment.json
task = Task(template_id=template_id, playbook=playbook_name,environment=environment_json)
self.project_api.project_project_id_tasks_post(task,project_id)
tasks = self.project_api.project_project_id_tasks_get(project_id)
return self.find_latest_task(tasks).id
......
......@@ -15,7 +15,7 @@ from __future__ import absolute_import
import unittest
from time import sleep
import datetime
import yaml
from semaphore_client.semaphore_helper import SemaphoreHelper
......@@ -30,22 +30,23 @@ class TestTask(unittest.TestCase):
if SemaphoreHelper.service_is_up(self.semaphore_base_url):
self.username = 'admin'
self.password = 'password'
self.project_name = 'test'
now = datetime.datetime.now()
self.project_name = 'project_name_test'+'_'+str(now)
self.private_key = '-----BEGIN RSA PRIVATE KEY-----MIIEowIBAAKCAQEAg0blRNV6cm3RTiivpzE8HR4JzKZRVIBZ7bxeNoMz0' \
'-----END RSA PRIVATE KEY-----'
vms = []
vm = {}
vm['role'] = 'master'
vm['public_ip'] = '192.168.1.10'
vm['user_name'] = 'user_name'
vm['public_ip'] = '127.0.0.1'
vm['semaphore'] = 'semaphore'
vms.append(vm)
vm['role'] = 'worker'
vm['public_ip'] = '192.168.1.11'
vm['public_ip'] = '127.0.0.1'
vm['role'] = 'worker'
vm['public_ip'] = '192.168.1.12'
vm['public_ip'] = '127.0.0.1'
vms.append(vm)
self.inventory_contents = yaml.dump( self.build_yml_inventory(vms),default_flow_style=False)
self.git_url = 'https://github.com/skoulouzis/playbooks.git'
self.git_url = 'https://github.com/QCDIS/playbooks.git'
self.playbook_name = 'get_ip_addresses.yaml'
self.semaphore_helper = SemaphoreHelper(self.semaphore_base_url, self.username, self.password)
......@@ -55,13 +56,21 @@ class TestTask(unittest.TestCase):
def testTask(self):
if SemaphoreHelper.service_is_up(self.semaphore_base_url):
project_id = self.semaphore_helper.create_project(self.project_name)
key_id = self.semaphore_helper.create_ssh_key(self.project_name, project_id, self.private_key)
inventory_id = self.semaphore_helper.create_inventory(self.project_name, project_id, key_id, self.inventory_contents)
repository_id = self.semaphore_helper.create_repository(self.project_name, project_id, key_id, self.git_url)
now = datetime.datetime.now()
key_name = 'key_name'+str(now)
key_id = self.semaphore_helper.create_ssh_key(key_name, project_id, self.private_key)
now = datetime.datetime.now()
inventory_name = 'inventory_name'+str(now)
inventory_id = self.semaphore_helper.create_inventory(inventory_name, project_id, key_id, self.inventory_contents)
now = datetime.datetime.now()
repository_name = 'repository_name'+str(now)
repository_id = self.semaphore_helper.create_repository(repository_name, project_id, key_id, self.git_url)
template_id = self.semaphore_helper.create_template(project_id, key_id, inventory_id, repository_id, self.playbook_name)
env_vars = {"SOME_VAR": "the contents"}
environment_id = self.semaphore_helper.create_environment(project_id,self.project_name,env_vars)
now = datetime.datetime.now()
environment_name = 'environment_name_name_'+str(now)
environment_id = self.semaphore_helper.create_environment(project_id,environment_name,env_vars)
task_id = self.semaphore_helper.execute_task(project_id, template_id, self.playbook_name,environment_id=environment_id)
for x in range(0, 2):
task = self.semaphore_helper.get_task(project_id, task_id)
......@@ -70,20 +79,20 @@ class TestTask(unittest.TestCase):
# print(task_output)
sleep(1)
task_id = self.semaphore_helper.execute_task(project_id, template_id, self.playbook_name)
for x in range(0, 2):
task = self.semaphore_helper.get_task(project_id, task_id)
print(task)
# task_output = self.semaphore_helper.get_task_output(project_id, task_id)
# print(task_output)
sleep(1)
task_id = self.semaphore_helper.execute_task(project_id, template_id, 'mount.yaml')
for x in range(0, 2):
task = self.semaphore_helper.get_task(project_id, task_id)
print(task)
# task_output = self.semaphore_helper.get_task_output(project_id, task_id)
# print(task_output)
sleep(1)
# task_id = self.semaphore_helper.execute_task(project_id, template_id, self.playbook_name)
# for x in range(0, 2):
# task = self.semaphore_helper.get_task(project_id, task_id)
# print(task)
# # task_output = self.semaphore_helper.get_task_output(project_id, task_id)
# # print(task_output)
# sleep(1)
# task_id = self.semaphore_helper.execute_task(project_id, template_id, 'get_ip_addresses.yaml')
# for x in range(0, 2):
# task = self.semaphore_helper.get_task(project_id, task_id)
# print(task)
# # task_output = self.semaphore_helper.get_task_output(project_id, task_id)
# # print(task_output)
# sleep(1)
......@@ -91,7 +100,7 @@ class TestTask(unittest.TestCase):
inventory = {}
all = {}
vars = {'ansible_ssh_common_args':'-o StrictHostKeyChecking=no'}
vars['ansible_ssh_user'] = vms[0]['user_name']
vars['ansible_ssh_user'] = vms[0]['semaphore']
children = {}
for vm in vms:
role = vm['role']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment