Skip to content

Commit

Permalink
Add test_image_name_from_url
Browse files Browse the repository at this point in the history
  • Loading branch information
dlobato committed May 2, 2024
1 parent 34c8141 commit 07f4489
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actions/install_image
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def main(attributes):

# In all other cases, copy the image
if image_name_from_url:
image = url.split("/")[-1]
image = url.rsplit("/", 1)[-1]
else:
image = "EOS-{}.swi".format(version)

Expand Down
36 changes: 36 additions & 0 deletions test/actions/test_install_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,42 @@ def test_success(self):
remove_file(image_file)
bootstrap.end_test()

def test_image_name_from_url(self):
bootstrap = Bootstrap(ztps_default_config=True)
version = random_string()
image = random_string()
url = "http://{}/{}".format(bootstrap.server, image)
bootstrap.ztps.set_definition_response(
actions=[
{
"action": "test_action",
"attributes": {"url": url, "version": version, "image_name_from_url": True},
},
{"action": "startup_config_action"},
]
)

action = get_action("install_image")
bootstrap.ztps.set_action_response("test_action", action)
bootstrap.ztps.set_action_response("startup_config_action", startup_config_action())
bootstrap.ztps.set_file_response(image, print_action())
bootstrap.start_test()

image_file = "{}/{}".format(bootstrap.flash, url.rsplit("/", 1)[-1])
try:
self.assertTrue(os.path.isfile(image_file))
self.assertTrue(bootstrap.success())
self.assertEqual(
eapi_log()[-1], "install source flash:{}".format(url.rsplit("/", 1)[-1])
)
except AssertionError as assertion:
print("Output: {}".format(bootstrap.output))
print("Error: {}".format(bootstrap.error))
raise_exception(assertion)
finally:
remove_file(image_file)
bootstrap.end_test()


if __name__ == "__main__":
unittest.main()

0 comments on commit 07f4489

Please sign in to comment.