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: ...@@ -79,11 +79,11 @@ class SemaphoreHelper:
return self.find_template(templates,playbook_name).id return self.find_template(templates,playbook_name).id
def execute_task(self, project_id, template_id, playbook_name,environment_id=None): def execute_task(self, project_id, template_id, playbook_name,environment_id=None):
environment_name = None environment_json = None
if environment_id: if environment_id:
environment = self.find_environment(project_id,environment_id=environment_id) environment = self.find_environment(project_id,environment_id=environment_id)
environment_name = environment.name environment_json = environment.json
task = Task(template_id=template_id, playbook=playbook_name,environment=environment_name) task = Task(template_id=template_id, playbook=playbook_name,environment=environment_json)
self.project_api.project_project_id_tasks_post(task,project_id) self.project_api.project_project_id_tasks_post(task,project_id)
tasks = self.project_api.project_project_id_tasks_get(project_id) tasks = self.project_api.project_project_id_tasks_get(project_id)
return self.find_latest_task(tasks).id return self.find_latest_task(tasks).id
......
...@@ -15,7 +15,7 @@ from __future__ import absolute_import ...@@ -15,7 +15,7 @@ from __future__ import absolute_import
import unittest import unittest
from time import sleep from time import sleep
import datetime
import yaml import yaml
from semaphore_client.semaphore_helper import SemaphoreHelper from semaphore_client.semaphore_helper import SemaphoreHelper
...@@ -30,22 +30,23 @@ class TestTask(unittest.TestCase): ...@@ -30,22 +30,23 @@ class TestTask(unittest.TestCase):
if SemaphoreHelper.service_is_up(self.semaphore_base_url): if SemaphoreHelper.service_is_up(self.semaphore_base_url):
self.username = 'admin' self.username = 'admin'
self.password = 'password' 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' \ self.private_key = '-----BEGIN RSA PRIVATE KEY-----MIIEowIBAAKCAQEAg0blRNV6cm3RTiivpzE8HR4JzKZRVIBZ7bxeNoMz0' \
'-----END RSA PRIVATE KEY-----' '-----END RSA PRIVATE KEY-----'
vms = [] vms = []
vm = {} vm = {}
vm['role'] = 'master' vm['role'] = 'master'
vm['public_ip'] = '192.168.1.10' vm['public_ip'] = '127.0.0.1'
vm['user_name'] = 'user_name' vm['semaphore'] = 'semaphore'
vms.append(vm) vms.append(vm)
vm['role'] = 'worker' vm['role'] = 'worker'
vm['public_ip'] = '192.168.1.11' vm['public_ip'] = '127.0.0.1'
vm['role'] = 'worker' vm['role'] = 'worker'
vm['public_ip'] = '192.168.1.12' vm['public_ip'] = '127.0.0.1'
vms.append(vm) vms.append(vm)
self.inventory_contents = yaml.dump( self.build_yml_inventory(vms),default_flow_style=False) 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.playbook_name = 'get_ip_addresses.yaml'
self.semaphore_helper = SemaphoreHelper(self.semaphore_base_url, self.username, self.password) self.semaphore_helper = SemaphoreHelper(self.semaphore_base_url, self.username, self.password)
...@@ -55,13 +56,21 @@ class TestTask(unittest.TestCase): ...@@ -55,13 +56,21 @@ class TestTask(unittest.TestCase):
def testTask(self): def testTask(self):
if SemaphoreHelper.service_is_up(self.semaphore_base_url): if SemaphoreHelper.service_is_up(self.semaphore_base_url):
project_id = self.semaphore_helper.create_project(self.project_name) 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) now = datetime.datetime.now()
inventory_id = self.semaphore_helper.create_inventory(self.project_name, project_id, key_id, self.inventory_contents) key_name = 'key_name'+str(now)
repository_id = self.semaphore_helper.create_repository(self.project_name, project_id, key_id, self.git_url) 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) template_id = self.semaphore_helper.create_template(project_id, key_id, inventory_id, repository_id, self.playbook_name)
env_vars = {"SOME_VAR": "the contents"} 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) task_id = self.semaphore_helper.execute_task(project_id, template_id, self.playbook_name,environment_id=environment_id)
for x in range(0, 2): for x in range(0, 2):
task = self.semaphore_helper.get_task(project_id, task_id) task = self.semaphore_helper.get_task(project_id, task_id)
...@@ -70,20 +79,20 @@ class TestTask(unittest.TestCase): ...@@ -70,20 +79,20 @@ class TestTask(unittest.TestCase):
# print(task_output) # print(task_output)
sleep(1) sleep(1)
task_id = self.semaphore_helper.execute_task(project_id, template_id, self.playbook_name) # task_id = self.semaphore_helper.execute_task(project_id, template_id, self.playbook_name)
for x in range(0, 2): # for x in range(0, 2):
task = self.semaphore_helper.get_task(project_id, task_id) # task = self.semaphore_helper.get_task(project_id, task_id)
print(task) # print(task)
# task_output = self.semaphore_helper.get_task_output(project_id, task_id) # # task_output = self.semaphore_helper.get_task_output(project_id, task_id)
# print(task_output) # # print(task_output)
sleep(1) # sleep(1)
task_id = self.semaphore_helper.execute_task(project_id, template_id, 'mount.yaml') # task_id = self.semaphore_helper.execute_task(project_id, template_id, 'get_ip_addresses.yaml')
for x in range(0, 2): # for x in range(0, 2):
task = self.semaphore_helper.get_task(project_id, task_id) # task = self.semaphore_helper.get_task(project_id, task_id)
print(task) # print(task)
# task_output = self.semaphore_helper.get_task_output(project_id, task_id) # # task_output = self.semaphore_helper.get_task_output(project_id, task_id)
# print(task_output) # # print(task_output)
sleep(1) # sleep(1)
...@@ -91,7 +100,7 @@ class TestTask(unittest.TestCase): ...@@ -91,7 +100,7 @@ class TestTask(unittest.TestCase):
inventory = {} inventory = {}
all = {} all = {}
vars = {'ansible_ssh_common_args':'-o StrictHostKeyChecking=no'} vars = {'ansible_ssh_common_args':'-o StrictHostKeyChecking=no'}
vars['ansible_ssh_user'] = vms[0]['user_name'] vars['ansible_ssh_user'] = vms[0]['semaphore']
children = {} children = {}
for vm in vms: for vm in vms:
role = vm['role'] 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