Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
8403213f
Commit
8403213f
authored
Jun 10, 2020
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed error with environment. It need the json not the name
parent
9b72148c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
30 deletions
+39
-30
semaphore_helper.py
...hon-client-generated/semaphore_client/semaphore_helper.py
+3
-3
test_task.py
semaphore-python-client-generated/test/test_task.py
+36
-27
No files found.
semaphore-python-client-generated/semaphore_client/semaphore_helper.py
View file @
8403213f
...
@@ -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
...
...
semaphore-python-client-generated/test/test_task.py
View file @
8403213f
...
@@ -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'
]
=
'1
92.168.1.10
'
vm
[
'public_ip'
]
=
'1
27.0.0.1
'
vm
[
'
user_name'
]
=
'user_nam
e'
vm
[
'
semaphore'
]
=
'semaphor
e'
vms
.
append
(
vm
)
vms
.
append
(
vm
)
vm
[
'role'
]
=
'worker'
vm
[
'role'
]
=
'worker'
vm
[
'public_ip'
]
=
'1
92.168.1.1
1'
vm
[
'public_ip'
]
=
'1
27.0.0.
1'
vm
[
'role'
]
=
'worker'
vm
[
'role'
]
=
'worker'
vm
[
'public_ip'
]
=
'1
92.168.1.12
'
vm
[
'public_ip'
]
=
'1
27.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_nam
e'
]
vars
[
'ansible_ssh_user'
]
=
vms
[
0
][
'
semaphor
e'
]
children
=
{}
children
=
{}
for
vm
in
vms
:
for
vm
in
vms
:
role
=
vm
[
'role'
]
role
=
vm
[
'role'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment