Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
slapos
Commits
c881dabf
Commit
c881dabf
authored
Oct 21, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
publish: move to GenericjIOAPIRecipe
parent
d29034b7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
4 deletions
+131
-4
slapos/recipe/publish.py
slapos/recipe/publish.py
+4
-4
slapos/test/recipe/test_publish.py
slapos/test/recipe/test_publish.py
+127
-0
No files found.
slapos/recipe/publish.py
View file @
c881dabf
...
...
@@ -27,12 +27,12 @@
from
__future__
import
print_function
import
zc.buildout
from
slapos.recipe.librecipe
import
wrap
from
slapos.recipe.librecipe
import
Generic
Slap
Recipe
from
slapos.recipe.librecipe
import
Generic
jIOAPI
Recipe
import
six
CONNECTION_PARAMETER_STRING
=
'connection-'
class
Recipe
(
Generic
Slap
Recipe
):
class
Recipe
(
Generic
jIOAPI
Recipe
):
def
__init__
(
self
,
buildout
,
name
,
options
):
super
(
Recipe
,
self
).
__init__
(
buildout
,
name
,
options
)
# Tell buildout about the sections we will access during install.
...
...
@@ -66,7 +66,7 @@ class Serialised(Recipe):
class
PublishSection
(
Generic
Slap
Recipe
):
class
PublishSection
(
Generic
jIOAPI
Recipe
):
"""
Take a list of "request" sections, and publish every connection parameter.
...
...
slapos/test/recipe/test_publish.py
0 → 100644
View file @
c881dabf
# coding: utf-8
import
json
import
httmock
import
os
import
unittest
import
tempfile
from
slapos.recipe
import
publish
from
slapos.recipe.librecipe
import
wrap
from
slapos.grid.SlapObject
import
SOFTWARE_INSTANCE_JSON_FILENAME
from
test_slaposconfiguration
import
APIRequestHandler
class
PublishTestMixin
(
object
):
def
setUp
(
self
):
"""Prepare files on filesystem."""
self
.
instance_root
=
tempfile
.
mkdtemp
()
self
.
instance_json_location
=
os
.
path
.
join
(
self
.
instance_root
,
SOFTWARE_INSTANCE_JSON_FILENAME
)
# do your tests inside try block and clean up in finally
self
.
buildout
=
{
"buildout"
:
{
"directory"
:
self
.
instance_root
},
"slap-connection"
:
{
"computer-id"
:
"COMP-12"
,
"partition-id"
:
"slappart12"
,
"server-url"
:
"http://127.0.0.1:80"
,
"software-release-url"
:
"foo.cfg"
,
},
}
def
tearDown
(
self
):
if
os
.
path
.
exists
(
self
.
instance_json_location
):
os
.
unlink
(
self
.
instance_json_location
)
os
.
rmdir
(
self
.
instance_root
)
def
test_publish_connection_information
(
self
):
"""Test proper call with new api"""
options
=
{
"foo"
:
"bar"
,
"hello"
:
"bye"
,
}
self
.
buildout
[
"publish"
]
=
options
if
self
.
serialised
:
connection_parameters
=
wrap
({
"foo"
:
"bar"
})
else
:
connection_parameters
=
{
"foo"
:
"bar"
}
instance_data
=
{
"reference"
:
"SOFTINST-12"
,
"connection_parameters"
:
connection_parameters
,
}
if
self
.
use_api
:
api_handler
=
APIRequestHandler
([
(
"/api/get/"
,
json
.
dumps
(
instance_data
)),
(
"/api/put/"
,
"{}"
)
])
else
:
with
open
(
self
.
instance_json_location
,
'w'
)
as
f
:
json
.
dump
(
instance_data
,
f
,
indent
=
2
)
api_handler
=
APIRequestHandler
([
(
"/api/put/"
,
"{}"
)
])
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
recipe
=
self
.
publish_recipe
(
self
.
buildout
,
"publish"
,
options
)
recipe
.
install
()
if
self
.
serialised
:
options
=
wrap
(
options
)
self
.
assertEqual
(
api_handler
.
request_payload_list
[
-
1
],
{
"reference"
:
instance_data
[
"reference"
],
"portal_type"
:
"Software Instance"
,
"connection_parameters"
:
options
}
)
def
test_publish_connection_not_needed
(
self
):
"""Test proper call with new api"""
options
=
{
"foo"
:
"bar"
,
"hello"
:
"bye"
,
}
self
.
buildout
[
"publish"
]
=
options
if
self
.
serialised
:
connection_parameters
=
wrap
(
options
)
else
:
connection_parameters
=
options
instance_data
=
{
"reference"
:
"SOFTINST-12"
,
"connection_parameters"
:
connection_parameters
,
}
if
self
.
use_api
:
api_handler
=
APIRequestHandler
([
(
"/api/get/"
,
json
.
dumps
(
instance_data
)),
])
else
:
with
open
(
self
.
instance_json_location
,
'w'
)
as
f
:
json
.
dump
(
instance_data
,
f
,
indent
=
2
)
api_handler
=
APIRequestHandler
([])
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
recipe
=
self
.
publish_recipe
(
self
.
buildout
,
"publish"
,
options
)
recipe
.
install
()
class
PublishWithLocalInstanceFile
(
PublishTestMixin
,
unittest
.
TestCase
):
use_api
=
False
publish_recipe
=
publish
.
Recipe
serialised
=
False
class
PublishWithApi
(
PublishTestMixin
,
unittest
.
TestCase
):
use_api
=
True
publish_recipe
=
publish
.
Recipe
serialised
=
False
class
PublishSerialiseWithLocalInstanceFile
(
PublishTestMixin
,
unittest
.
TestCase
):
use_api
=
False
publish_recipe
=
publish
.
Serialised
serialised
=
True
class
PublishSerialiseWithApi
(
PublishTestMixin
,
unittest
.
TestCase
):
use_api
=
True
publish_recipe
=
publish
.
Serialised
serialised
=
True
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