Fix tests related to blueprint name changes

This commit is contained in:
Brian C. Lane 2018-08-21 15:08:58 -07:00
parent b198c6e498
commit 7773be2bda
5 changed files with 113 additions and 110 deletions

View File

@ -166,7 +166,9 @@ make DESTDIR=$RPM_BUILD_ROOT mandir=%{_mandir} install
# Install example blueprints from the test suite.
# This path MUST match the lorax-composer.service blueprint path.
mkdir -p $RPM_BUILD_ROOT/var/lib/lorax/composer/blueprints/
cp ./tests/pylorax/blueprints/*toml $RPM_BUILD_ROOT/var/lib/lorax/composer/blueprints/
for bp in example-http-server.toml example-development.toml example-atlas.toml; do
cp ./tests/pylorax/blueprints/$bp $RPM_BUILD_ROOT/var/lib/lorax/composer/blueprints/
done
%pre composer
getent group weldr >/dev/null 2>&1 || groupadd -r weldr >/dev/null 2>&1 || :

View File

@ -51,15 +51,15 @@ class BlueprintsTest(unittest.TestCase):
rc = blueprints_list("/run/weldr/api.socket", 0, [], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
self.assertTrue("http-server" in output)
self.assertTrue("example-http-server" in output)
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_show(self):
"""blueprints show"""
with captured_output() as (out, _):
blueprints_show("/run/weldr/api.socket", 0, ["http-server"], show_json=False)
blueprints_show("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
output = out.getvalue().strip()
self.assertTrue("http-server" in output)
self.assertTrue("example-http-server" in output)
self.assertTrue("[[packages]]" in output)
self.assertTrue("[[modules]]" in output)
@ -67,23 +67,23 @@ class BlueprintsTest(unittest.TestCase):
def test_changes(self):
"""blueprints changes"""
with captured_output() as (out, _):
rc = blueprints_changes("/run/weldr/api.socket", 0, ["http-server"], show_json=False)
rc = blueprints_changes("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
self.assertTrue("http-server" in output)
self.assertTrue("Recipe http-server, version 0.0.1 saved." in output)
self.assertTrue("example-http-server" in output)
self.assertTrue("Recipe example-http-server, version 0.0.1 saved." in output)
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_diff(self):
"""blueprints diff"""
# Get the oldest commit, it should be 2nd to last line
with captured_output() as (out, _):
rc = blueprints_changes("/run/weldr/api.socket", 0, ["http-server"], show_json=False)
rc = blueprints_changes("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
output = out.getvalue().strip().splitlines()
first_commit = output[-2].split()[1]
with captured_output() as (out, _):
rc = blueprints_diff("/run/weldr/api.socket", 0, ["http-server", first_commit, "HEAD"], show_json=False)
rc = blueprints_diff("/run/weldr/api.socket", 0, ["example-http-server", first_commit, "HEAD"], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
self.assertTrue("Changed Version" in output)
@ -91,40 +91,40 @@ class BlueprintsTest(unittest.TestCase):
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_save_0(self):
"""blueprints save"""
blueprints_save("/run/weldr/api.socket", 0, ["http-server"], show_json=False)
self.assertTrue(os.path.exists("http-server.toml"))
blueprints_save("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
self.assertTrue(os.path.exists("example-http-server.toml"))
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_save_1(self):
"""blueprints push"""
rc = blueprints_push("/run/weldr/api.socket", 0, ["http-server.toml"], show_json=False)
rc = blueprints_push("/run/weldr/api.socket", 0, ["example-http-server.toml"], show_json=False)
self.assertTrue(rc == 0)
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_delete(self):
"""blueprints delete"""
rc = blueprints_delete("/run/weldr/api.socket", 0, ["development"], show_json=False)
rc = blueprints_delete("/run/weldr/api.socket", 0, ["example-development"], show_json=False)
self.assertTrue(rc == 0)
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_depsolve(self):
"""blueprints depsolve"""
with captured_output() as (out, _):
rc = blueprints_depsolve("/run/weldr/api.socket", 0, ["http-server"], show_json=False)
rc = blueprints_depsolve("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
self.assertTrue("blueprint: http-server v" in output)
self.assertTrue("blueprint: example-http-server v" in output)
self.assertTrue("httpd" in output)
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_freeze_show(self):
"""blueprints freeze show"""
with captured_output() as (out, _):
rc = blueprints_freeze("/run/weldr/api.socket", 0, ["show", "http-server"], show_json=False)
rc = blueprints_freeze("/run/weldr/api.socket", 0, ["show", "example-http-server"], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
self.assertTrue("version" in output)
self.assertTrue("http-server" in output)
self.assertTrue("example-http-server" in output)
self.assertTrue("x86_64" in output)
self.assertTrue("[[packages]]" in output)
self.assertTrue("[[modules]]" in output)
@ -132,18 +132,18 @@ class BlueprintsTest(unittest.TestCase):
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_freeze_save(self):
"""blueprints freeze save"""
rc = blueprints_freeze("/run/weldr/api.socket", 0, ["save", "http-server"], show_json=False)
rc = blueprints_freeze("/run/weldr/api.socket", 0, ["save", "example-http-server"], show_json=False)
self.assertTrue(rc == 0)
self.assertTrue(os.path.exists("http-server.frozen.toml"))
self.assertTrue(os.path.exists("example-http-server.frozen.toml"))
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_freeze(self):
"""blueprints freeze"""
with captured_output() as (out, _):
rc = blueprints_freeze("/run/weldr/api.socket", 0, ["http-server"], show_json=False)
rc = blueprints_freeze("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
self.assertTrue("blueprint: http-server v" in output)
self.assertTrue("blueprint: example-http-server v" in output)
self.assertTrue("httpd" in output)
self.assertTrue("x86_64" in output)
@ -158,17 +158,17 @@ class BlueprintsTest(unittest.TestCase):
"""blueprints undo"""
# Get the oldest commit, it should be 2nd to last line
with captured_output() as (out, _):
rc = blueprints_changes("/run/weldr/api.socket", 0, ["http-server"], show_json=False)
rc = blueprints_changes("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
output = out.getvalue().strip().splitlines()
first_commit = output[-2].split()[1]
with captured_output() as (out, _):
rc = blueprints_undo("/run/weldr/api.socket", 0, ["http-server", first_commit, "HEAD"], show_json=False)
rc = blueprints_undo("/run/weldr/api.socket", 0, ["example-http-server", first_commit, "HEAD"], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_workspace(self):
"""blueprints workspace"""
rc = blueprints_push("/run/weldr/api.socket", 0, ["http-server.toml"], show_json=False)
rc = blueprints_push("/run/weldr/api.socket", 0, ["example-http-server.toml"], show_json=False)
self.assertTrue(rc == 0)

View File

@ -265,20 +265,20 @@ version = "2.7.*"
def test_06_read_recipe(self):
"""Test reading a recipe from a commit"""
commits = recipes.list_commits(self.repo, "master", "http-server.toml")
commits = recipes.list_commits(self.repo, "master", "example-http-server.toml")
self.assertEqual(len(commits), 1, "Wrong number of commits: %s" % commits)
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server")
recipe = recipes.read_recipe_commit(self.repo, "master", "example-http-server")
self.assertNotEqual(recipe, None)
self.assertEqual(recipe["name"], "http-server")
self.assertEqual(recipe["name"], "example-http-server")
# Read by commit id
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server", commits[0].commit)
recipe = recipes.read_recipe_commit(self.repo, "master", "example-http-server", commits[0].commit)
self.assertNotEqual(recipe, None)
self.assertEqual(recipe["name"], "http-server")
self.assertEqual(recipe["name"], "example-http-server")
# Read the recipe and its commit id
(commit_id, recipe) = recipes.read_recipe_and_id(self.repo, "master", "http-server", commits[0].commit)
(commit_id, recipe) = recipes.read_recipe_and_id(self.repo, "master", "example-http-server", commits[0].commit)
self.assertEqual(commit_id, commits[0].commit)
def test_07_tag_commit(self):
@ -286,44 +286,44 @@ version = "2.7.*"
result = recipes.tag_file_commit(self.repo, "master", "not-a-file")
self.assertEqual(result, None)
result = recipes.tag_recipe_commit(self.repo, "master", "http-server")
result = recipes.tag_recipe_commit(self.repo, "master", "example-http-server")
self.assertNotEqual(result, None)
commits = recipes.list_commits(self.repo, "master", "http-server.toml")
commits = recipes.list_commits(self.repo, "master", "example-http-server.toml")
self.assertEqual(len(commits), 1, "Wrong number of commits: %s" % commits)
self.assertEqual(commits[0].revision, 1)
def test_08_delete_recipe(self):
"""Test deleting a file from a branch"""
oid = recipes.delete_recipe(self.repo, "master", "http-server")
oid = recipes.delete_recipe(self.repo, "master", "example-http-server")
self.assertNotEqual(oid, None)
master_files = recipes.list_branch_files(self.repo, "master")
self.assertEqual("http-server.toml" in master_files, False)
self.assertEqual("example-http-server.toml" in master_files, False)
def test_09_revert_commit(self):
"""Test reverting a file on a branch"""
commits = recipes.list_commits(self.repo, "master", "http-server.toml")
commits = recipes.list_commits(self.repo, "master", "example-http-server.toml")
revert_to = commits[0].commit
oid = recipes.revert_recipe(self.repo, "master", "http-server", revert_to)
oid = recipes.revert_recipe(self.repo, "master", "example-http-server", revert_to)
self.assertNotEqual(oid, None)
commits = recipes.list_commits(self.repo, "master", "http-server.toml")
commits = recipes.list_commits(self.repo, "master", "example-http-server.toml")
self.assertEqual(len(commits), 2, "Wrong number of commits: %s" % commits)
self.assertEqual(commits[0].message, "http-server.toml reverted to commit %s" % revert_to)
self.assertEqual(commits[0].message, "example-http-server.toml reverted to commit %s" % revert_to)
def test_10_tag_new_commit(self):
"""Test tagging a newer commit of a recipe"""
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server")
recipe = recipes.read_recipe_commit(self.repo, "master", "example-http-server")
recipe["description"] = "A modified description"
oid = recipes.commit_recipe(self.repo, "master", recipe)
self.assertNotEqual(oid, None)
# Tag the new commit
result = recipes.tag_recipe_commit(self.repo, "master", "http-server")
result = recipes.tag_recipe_commit(self.repo, "master", "example-http-server")
self.assertNotEqual(result, None)
commits = recipes.list_commits(self.repo, "master", "http-server.toml")
commits = recipes.list_commits(self.repo, "master", "example-http-server.toml")
self.assertEqual(len(commits), 3, "Wrong number of commits: %s" % commits)
self.assertEqual(commits[0].revision, 2)

View File

@ -134,15 +134,16 @@ class ServerTestCase(unittest.TestCase):
def test_02_blueprints_list(self):
"""Test the /api/v0/blueprints/list route"""
list_dict = {"blueprints":["atlas", "custom-base", "development", "glusterfs", "http-server",
"jboss", "kubernetes"], "limit":20, "offset":0, "total":7}
list_dict = {"blueprints":["example-atlas", "example-custom-base", "example-development",
"example-glusterfs", "example-http-server", "example-jboss",
"example-kubernetes"], "limit":20, "offset":0, "total":7}
resp = self.server.get("/api/v0/blueprints/list")
data = json.loads(resp.data)
self.assertEqual(data, list_dict)
def test_03_blueprints_info_1(self):
"""Test the /api/v0/blueprints/info route with one blueprint"""
info_dict_1 = {"changes":[{"changed":False, "name":"http-server"}],
info_dict_1 = {"changes":[{"changed":False, "name":"example-http-server"}],
"errors":[],
"blueprints":[{"description":"An example http server with PHP and MySQL support.",
"modules":[{"name":"httpd", "version":"2.4.*"},
@ -150,25 +151,25 @@ class ServerTestCase(unittest.TestCase):
{"name":"mod_ssl", "version":"2.4.*"},
{"name":"php", "version":"7.2.4"},
{"name": "php-mysqlnd", "version":"7.2.4"}],
"name":"http-server",
"name":"example-http-server",
"packages": [{"name":"openssh-server", "version": "7.*"},
{"name": "rsync", "version": "3.1.*"},
{"name": "tmux", "version": "2.7"}],
"groups": [],
"version": "0.0.1"}]}
resp = self.server.get("/api/v0/blueprints/info/http-server")
resp = self.server.get("/api/v0/blueprints/info/example-http-server")
data = json.loads(resp.data)
self.assertEqual(data, info_dict_1)
def test_03_blueprints_info_2(self):
"""Test the /api/v0/blueprints/info route with 2 blueprints"""
info_dict_2 = {"changes":[{"changed":False, "name":"glusterfs"},
{"changed":False, "name":"http-server"}],
info_dict_2 = {"changes":[{"changed":False, "name":"example-glusterfs"},
{"changed":False, "name":"example-http-server"}],
"errors":[],
"blueprints":[{"description": "An example GlusterFS server with samba",
"modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}],
"name":"glusterfs",
"name":"example-glusterfs",
"packages":[{"name":"samba", "version":"4.8.*"}],
"groups": [],
"version": "0.0.1"},
@ -178,14 +179,14 @@ class ServerTestCase(unittest.TestCase):
{"name":"mod_ssl", "version":"2.4.*"},
{"name":"php", "version":"7.2.4"},
{"name": "php-mysqlnd", "version":"7.2.4"}],
"name":"http-server",
"name":"example-http-server",
"packages": [{"name":"openssh-server", "version": "7.*"},
{"name": "rsync", "version": "3.1.*"},
{"name": "tmux", "version": "2.7"}],
"groups": [],
"version": "0.0.1"},
]}
resp = self.server.get("/api/v0/blueprints/info/http-server,glusterfs")
resp = self.server.get("/api/v0/blueprints/info/example-http-server,example-glusterfs")
data = json.loads(resp.data)
self.assertEqual(data, info_dict_2)
@ -201,7 +202,7 @@ class ServerTestCase(unittest.TestCase):
def test_04_blueprints_changes(self):
"""Test the /api/v0/blueprints/changes route"""
resp = self.server.get("/api/v0/blueprints/changes/http-server")
resp = self.server.get("/api/v0/blueprints/changes/example-http-server")
data = json.loads(resp.data)
# Can't compare a whole dict since commit hash and timestamps will change.
@ -210,12 +211,12 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(data["offset"], 0)
self.assertEqual(len(data["errors"]), 0)
self.assertEqual(len(data["blueprints"]), 1)
self.assertEqual(data["blueprints"][0]["name"], "http-server")
self.assertEqual(data["blueprints"][0]["name"], "example-http-server")
self.assertEqual(len(data["blueprints"][0]["changes"]), 1)
def test_04a_blueprints_diff_empty_ws(self):
"""Test the /api/v0/diff/NEWEST/WORKSPACE with empty workspace"""
resp = self.server.get("/api/v0/blueprints/diff/glusterfs/NEWEST/WORKSPACE")
resp = self.server.get("/api/v0/blueprints/diff/example-glusterfs/NEWEST/WORKSPACE")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
self.assertEqual(data, {"diff": []})
@ -223,7 +224,7 @@ class ServerTestCase(unittest.TestCase):
def test_05_blueprints_new_json(self):
"""Test the /api/v0/blueprints/new route with json blueprint"""
test_blueprint = {"description": "An example GlusterFS server with samba",
"name":"glusterfs",
"name":"example-glusterfs",
"version": "0.2.0",
"modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}],
@ -237,7 +238,7 @@ class ServerTestCase(unittest.TestCase):
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/info/glusterfs")
resp = self.server.get("/api/v0/blueprints/info/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
@ -246,14 +247,14 @@ class ServerTestCase(unittest.TestCase):
def test_06_blueprints_new_toml(self):
"""Test the /api/v0/blueprints/new route with toml blueprint"""
test_blueprint = open(joinpaths(self.examples_path, "glusterfs.toml"), "rb").read()
test_blueprint = open(joinpaths(self.examples_path, "example-glusterfs.toml"), "rb").read()
resp = self.server.post("/api/v0/blueprints/new",
data=test_blueprint,
content_type="text/x-toml")
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/info/glusterfs")
resp = self.server.get("/api/v0/blueprints/info/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
@ -274,7 +275,7 @@ class ServerTestCase(unittest.TestCase):
def test_07_blueprints_ws_json(self):
"""Test the /api/v0/blueprints/workspace route with json blueprint"""
test_blueprint = {"description": "An example GlusterFS server with samba, ws version",
"name":"glusterfs",
"name":"example-glusterfs",
"version": "0.3.0",
"modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}],
@ -288,7 +289,7 @@ class ServerTestCase(unittest.TestCase):
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/info/glusterfs")
resp = self.server.get("/api/v0/blueprints/info/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
@ -296,12 +297,12 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(blueprints[0], test_blueprint)
changes = data.get("changes")
self.assertEqual(len(changes), 1)
self.assertEqual(changes[0], {"name":"glusterfs", "changed":True})
self.assertEqual(changes[0], {"name":"example-glusterfs", "changed":True})
def test_08_blueprints_ws_toml(self):
"""Test the /api/v0/blueprints/workspace route with toml blueprint"""
test_blueprint = {"description": "An example GlusterFS server with samba, ws version",
"name":"glusterfs",
"name":"example-glusterfs",
"version": "0.4.0",
"modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}],
@ -315,7 +316,7 @@ class ServerTestCase(unittest.TestCase):
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/info/glusterfs")
resp = self.server.get("/api/v0/blueprints/info/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
@ -323,7 +324,7 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(blueprints[0], test_blueprint)
changes = data.get("changes")
self.assertEqual(len(changes), 1)
self.assertEqual(changes[0], {"name":"glusterfs", "changed":True})
self.assertEqual(changes[0], {"name":"example-glusterfs", "changed":True})
def test_09_blueprints_ws_delete(self):
"""Test DELETE /api/v0/blueprints/workspace/<blueprint_name>"""
@ -331,12 +332,12 @@ class ServerTestCase(unittest.TestCase):
self.test_07_blueprints_ws_json()
# Delete it
resp = self.server.delete("/api/v0/blueprints/workspace/glusterfs")
resp = self.server.delete("/api/v0/blueprints/workspace/example-glusterfs")
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
# Make sure it isn't the workspace copy and that changed is False
resp = self.server.get("/api/v0/blueprints/info/glusterfs")
resp = self.server.get("/api/v0/blueprints/info/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
@ -344,24 +345,24 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(blueprints[0]["version"], "0.2.1")
changes = data.get("changes")
self.assertEqual(len(changes), 1)
self.assertEqual(changes[0], {"name":"glusterfs", "changed":False})
self.assertEqual(changes[0], {"name":"example-glusterfs", "changed":False})
def test_10_blueprints_delete(self):
"""Test DELETE /api/v0/blueprints/delete/<blueprint_name>"""
resp = self.server.delete("/api/v0/blueprints/delete/glusterfs")
resp = self.server.delete("/api/v0/blueprints/delete/example-glusterfs")
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
# Make sure glusterfs is no longer in the list of blueprints
# Make sure example-glusterfs is no longer in the list of blueprints
resp = self.server.get("/api/v0/blueprints/list")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
self.assertEqual("glusterfs" in blueprints, False)
self.assertEqual("example-glusterfs" in blueprints, False)
def test_11_blueprints_undo(self):
"""Test POST /api/v0/blueprints/undo/<blueprint_name>/<commit>"""
resp = self.server.get("/api/v0/blueprints/changes/glusterfs")
resp = self.server.get("/api/v0/blueprints/changes/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
@ -373,11 +374,11 @@ class ServerTestCase(unittest.TestCase):
# Revert it to the first commit
commit = changes[-1]["commit"]
resp = self.server.post("/api/v0/blueprints/undo/glusterfs/%s" % commit)
resp = self.server.post("/api/v0/blueprints/undo/example-glusterfs/%s" % commit)
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/changes/glusterfs")
resp = self.server.get("/api/v0/blueprints/changes/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
@ -386,16 +387,16 @@ class ServerTestCase(unittest.TestCase):
changes = blueprints[0].get("changes")
self.assertEqual(len(changes) > 1, True)
expected_msg = "glusterfs.toml reverted to commit %s" % commit
expected_msg = "example-glusterfs.toml reverted to commit %s" % commit
self.assertEqual(changes[0]["message"], expected_msg)
def test_12_blueprints_tag(self):
"""Test POST /api/v0/blueprints/tag/<blueprint_name>"""
resp = self.server.post("/api/v0/blueprints/tag/glusterfs")
resp = self.server.post("/api/v0/blueprints/tag/example-glusterfs")
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/changes/glusterfs")
resp = self.server.get("/api/v0/blueprints/changes/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
@ -408,7 +409,7 @@ class ServerTestCase(unittest.TestCase):
def test_13_blueprints_diff(self):
"""Test /api/v0/blueprints/diff/<blueprint_name>/<from_commit>/<to_commit>"""
resp = self.server.get("/api/v0/blueprints/changes/glusterfs")
resp = self.server.get("/api/v0/blueprints/changes/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
@ -426,14 +427,14 @@ class ServerTestCase(unittest.TestCase):
print(changes)
# Get the differences between the two commits
resp = self.server.get("/api/v0/blueprints/diff/glusterfs/%s/%s" % (from_commit, to_commit))
resp = self.server.get("/api/v0/blueprints/diff/example-glusterfs/%s/%s" % (from_commit, to_commit))
data = json.loads(resp.data)
self.assertNotEqual(data, None)
self.assertEqual(data, {"diff": [{"new": {"Version": "0.0.1"}, "old": {"Version": "0.2.1"}}]})
# Write to the workspace and check the diff
test_blueprint = {"description": "An example GlusterFS server with samba, ws version",
"name":"glusterfs",
"name":"example-glusterfs",
"version": "0.3.0",
"modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}],
@ -447,7 +448,7 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(data, {"status":True})
# Get the differences between the newest commit and the workspace
resp = self.server.get("/api/v0/blueprints/diff/glusterfs/NEWEST/WORKSPACE")
resp = self.server.get("/api/v0/blueprints/diff/example-glusterfs/NEWEST/WORKSPACE")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
result = {"diff": [{"new": {"Description": "An example GlusterFS server with samba, ws version"},
@ -460,13 +461,13 @@ class ServerTestCase(unittest.TestCase):
def test_14_blueprints_depsolve(self):
"""Test /api/v0/blueprints/depsolve/<blueprint_names>"""
resp = self.server.get("/api/v0/blueprints/depsolve/glusterfs")
resp = self.server.get("/api/v0/blueprints/depsolve/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
self.assertNotEqual(blueprints, None)
self.assertEqual(len(blueprints), 1)
self.assertEqual(blueprints[0]["blueprint"]["name"], "glusterfs")
self.assertEqual(blueprints[0]["blueprint"]["name"], "example-glusterfs")
self.assertEqual(len(blueprints[0]["dependencies"]) > 10, True)
self.assertFalse(data.get("errors"))
@ -495,14 +496,14 @@ class ServerTestCase(unittest.TestCase):
def test_15_blueprints_freeze(self):
"""Test /api/v0/blueprints/freeze/<blueprint_names>"""
resp = self.server.get("/api/v0/blueprints/freeze/glusterfs")
resp = self.server.get("/api/v0/blueprints/freeze/example-glusterfs")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
self.assertNotEqual(blueprints, None)
self.assertEqual(len(blueprints), 1)
self.assertTrue(len(blueprints[0]["blueprint"]["modules"]) > 0)
self.assertEqual(blueprints[0]["blueprint"]["name"], "glusterfs")
self.assertEqual(blueprints[0]["blueprint"]["name"], "example-glusterfs")
evra = blueprints[0]["blueprint"]["modules"][0]["version"]
self.assertEqual(len(evra) > 10, True)
@ -695,7 +696,7 @@ class ServerTestCase(unittest.TestCase):
def test_blueprint_new_branch(self):
"""Test the /api/v0/blueprints/new route with a new branch"""
test_blueprint = {"description": "An example GlusterFS server with samba",
"name":"glusterfs",
"name":"example-glusterfs",
"version": "0.2.0",
"modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}],
@ -709,7 +710,7 @@ class ServerTestCase(unittest.TestCase):
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/info/glusterfs?branch=test")
resp = self.server.get("/api/v0/blueprints/info/example-glusterfs?branch=test")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
@ -770,7 +771,7 @@ class ServerTestCase(unittest.TestCase):
def test_compose_02_bad_type(self):
"""Test that using an unsupported image type failes"""
test_compose = {"blueprint_name": "glusterfs",
test_compose = {"blueprint_name": "example-glusterfs",
"compose_type": "snakes",
"branch": "master"}
@ -854,7 +855,7 @@ class ServerTestCase(unittest.TestCase):
def test_compose_11_create_failed(self):
"""Test the /api/v0/compose routes with a failed test compose"""
test_compose = {"blueprint_name": "glusterfs",
test_compose = {"blueprint_name": "example-glusterfs",
"compose_type": "tar",
"branch": "master"}
@ -940,7 +941,7 @@ class ServerTestCase(unittest.TestCase):
def test_compose_12_create_finished(self):
"""Test the /api/v0/compose routes with a finished test compose"""
test_compose = {"blueprint_name": "custom-base",
test_compose = {"blueprint_name": "example-custom-base",
"compose_type": "tar",
"branch": "master"}
@ -1032,11 +1033,11 @@ class ServerTestCase(unittest.TestCase):
def test_compose_13_status_filter(self):
"""Test filter arguments on the /api/v0/compose/status route"""
# Get a couple compose results going so we have something to filter
test_compose_fail = {"blueprint_name": "glusterfs",
test_compose_fail = {"blueprint_name": "example-glusterfs",
"compose_type": "tar",
"branch": "master"}
test_compose_success = {"blueprint_name": "custom-base",
test_compose_success = {"blueprint_name": "example-custom-base",
"compose_type": "tar",
"branch": "master"}
@ -1140,10 +1141,10 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.get("/api/v0/blueprints/info/" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.get("/api/v0/blueprints/info/http-server?branch=" + UTF8_TEST_STRING)
resp = self.server.get("/api/v0/blueprints/info/example-http-server?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.get("/api/v0/blueprints/info/http-server?format=" + UTF8_TEST_STRING)
resp = self.server.get("/api/v0/blueprints/info/example-http-server?format=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_blueprints_changes_input(self):
@ -1152,7 +1153,7 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.get("/api/v0/blueprints/changes/" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.get("/api/v0/blueprints/changes/http-server?branch=" + UTF8_TEST_STRING)
resp = self.server.get("/api/v0/blueprints/changes/example-http-server?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_blueprints_new_input(self):
@ -1172,7 +1173,7 @@ class ServerTestCase(unittest.TestCase):
content_type="application/json")
self.assertInputError(resp)
test_blueprint["name"] = "glusterfs"
test_blueprint["name"] = "example-glusterfs"
resp = self.server.post("/api/v0/blueprints/new?branch=" + UTF8_TEST_STRING,
data=json.dumps(test_blueprint),
content_type="application/json")
@ -1183,7 +1184,7 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.delete("/api/v0/blueprints/delete/" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.delete("/api/v0/blueprints/delete/http-server?branch=" + UTF8_TEST_STRING)
resp = self.server.delete("/api/v0/blueprints/delete/example-http-server?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_blueprints_workspace_input(self):
@ -1202,7 +1203,7 @@ class ServerTestCase(unittest.TestCase):
content_type="application/json")
self.assertInputError(resp)
test_blueprint["name"] = "glusterfs"
test_blueprint["name"] = "example-glusterfs"
resp = self.server.post("/api/v0/blueprints/workspace?branch=" + UTF8_TEST_STRING,
data=json.dumps(test_blueprint),
content_type="application/json")
@ -1213,7 +1214,7 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.delete("/api/v0/blueprints/workspace/" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.delete("/api/v0/blueprints/workspace/http-server?branch=" + UTF8_TEST_STRING)
resp = self.server.delete("/api/v0/blueprints/workspace/example-http-server?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_blueprints_undo_input(self):
@ -1221,7 +1222,7 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.post("/api/v0/blueprints/undo/" + UTF8_TEST_STRING + "/deadbeef")
self.assertInputError(resp)
resp = self.server.post("/api/v0/blueprints/undo/http-server/deadbeef?branch=" + UTF8_TEST_STRING)
resp = self.server.post("/api/v0/blueprints/undo/example-http-server/deadbeef?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_blueprints_tag_input(self):
@ -1229,7 +1230,7 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.post("/api/v0/blueprints/tag/" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.post("/api/v0/blueprints/tag/http-server?branch=" + UTF8_TEST_STRING)
resp = self.server.post("/api/v0/blueprints/tag/example-http-server?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_blueprints_diff_input(self):
@ -1238,7 +1239,7 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.get("/api/v0/blueprints/diff/" + UTF8_TEST_STRING + "/NEWEST/WORKSPACE")
self.assertInputError(resp)
resp = self.server.get("/api/v0/blueprints/diff/http-server/NEWEST/WORKSPACE?branch=" + UTF8_TEST_STRING)
resp = self.server.get("/api/v0/blueprints/diff/example-http-server/NEWEST/WORKSPACE?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_blueprints_freeze_input(self):
@ -1246,10 +1247,10 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.get("/api/v0/blueprints/freeze/" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.get("/api/v0/blueprints/freeze/http-server?branch=" + UTF8_TEST_STRING)
resp = self.server.get("/api/v0/blueprints/freeze/example-http-server?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.get("/api/v0/blueprints/freeze/http-server?format=" + UTF8_TEST_STRING)
resp = self.server.get("/api/v0/blueprints/freeze/example-http-server?format=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_blueprints_depsolve_input(self):
@ -1257,7 +1258,7 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.get("/api/v0/blueprints/depsolve/" + UTF8_TEST_STRING)
self.assertInputError(resp)
resp = self.server.get("/api/v0/blueprints/depsolve/http-server?branch=" + UTF8_TEST_STRING)
resp = self.server.get("/api/v0/blueprints/depsolve/example-http-server?branch=" + UTF8_TEST_STRING)
self.assertInputError(resp)
def test_projects_info_input(self):

View File

@ -33,7 +33,7 @@ class WorkspaceTest(unittest.TestCase):
self.results_path = "./tests/pylorax/results/"
self.examples_path = "./tests/pylorax/blueprints/"
recipe_path = joinpaths(self.examples_path, "http-server.toml")
recipe_path = joinpaths(self.examples_path, "example-http-server.toml")
f = open(recipe_path, 'rb')
self.example_recipe = recipes.recipe_from_toml(f.read())
@ -58,13 +58,13 @@ class WorkspaceTest(unittest.TestCase):
workspace_write(self.repo, "master", self.example_recipe)
# The file should have ended up here
ws_recipe_path = joinpaths(self.repo_dir, "git", "workspace", "master", "http-server.toml")
ws_recipe_path = joinpaths(self.repo_dir, "git", "workspace", "master", "example-http-server.toml")
self.assertEqual(os.path.exists(ws_recipe_path), True)
def test_04_workspace_read(self):
"""Test the workspace_read function"""
# The recipe was written by the workspace_write test. Read it and compare with the source recipe.
recipe = workspace_read(self.repo, "master", "http-server")
recipe = workspace_read(self.repo, "master", "example-http-server")
self.assertEqual(self.example_recipe, recipe)
def test_04_workspace_read_ioerror(self):
@ -72,14 +72,14 @@ class WorkspaceTest(unittest.TestCase):
# The recipe was written by the workspace_write test.
with self.assertRaises(recipes.RecipeFileError):
with mock.patch('pylorax.api.workspace.recipe_from_toml', side_effect=IOError('TESTING')):
workspace_read(self.repo, "master", "http-server")
workspace_read(self.repo, "master", "example-http-server")
def test_05_workspace_delete(self):
"""Test the workspace_delete function"""
ws_recipe_path = joinpaths(self.repo_dir, "git", "workspace", "master", "http-server.toml")
ws_recipe_path = joinpaths(self.repo_dir, "git", "workspace", "master", "example-http-server.toml")
self.assertEqual(os.path.exists(ws_recipe_path), True)
workspace_delete(self.repo, "master", "http-server")
workspace_delete(self.repo, "master", "example-http-server")
self.assertEqual(os.path.exists(ws_recipe_path), False)
def test_05_workspace_delete_non_existing(self):