Skip to content

Commit

Permalink
Merge pull request #196 from manofcolombia/master
Browse files Browse the repository at this point in the history
updated upgradepackage and unit_test workflow as an example of end to end ftd upgrade
  • Loading branch information
marksull authored Apr 28, 2024
2 parents 7b4193b + d540004 commit 648b8ac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def post(self):
response = self.fmc.send_to_api(
method="post", url=self.URL, json_data=json_data
)
return response["deviceList"]
return response

def put(self):
"""PUT method for API for DeploymentRequests not supported."""
Expand Down
7 changes: 7 additions & 0 deletions fmcapi/api_objects/update_packages/upgradepackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class Upgrades(APIClassTemplate):
"upgradePackage",
"targets",
"pushUpgradeFileOnly",
"readinessCheckOnly",
"enableUpgradeRevert",
"autoUpgradeCancel",
]
REQUIRED_FOR_POST = [
"upgradePackage",
"targets"
]
VALID_FOR_KWARGS = VALID_JSON_DATA + []
URL_SUFFIX = "/updates/upgrades"
Expand Down
42 changes: 38 additions & 4 deletions unit_tests/upgrades.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import logging
import fmcapi
import time
from unit_tests import wait_for_task
from .wait_for_task import wait_for_task


def test__upgrades(fmc):
logging.info(
"Test UpgradePackages/ApplicableDevices/Upgrades with Task."
" This will copy the listed upgrade file to registered devices"
"""Test UpgradePackages/ApplicableDevices/Upgrades with Task.
This will copy the listed upgrade file to registered devices
Commented lines at the bottom show how to trigger readiness check, the actual upgrade process,
and the post upgrade deployment.
NOTE: this script will do this to ALL applicable devices based on the package_name given.
example: you have 5 FTDvs and you only want to upgrade 2 of them. Input here is just the package_name.
Script will add all eligible devices for the particular file given to the list of devices to run against.
Potentially resulting in upgrading all 5 FTDv unintentionally.
"""
)

package_name = "Cisco_FTD_Patch-6.3.0.3-77.sh.REL.tar"
package_name = "Cisco_FTD_Patch-7.4.1.1-12.sh.REL.tar"
device_list = []

logging.info("All UpgradePackages -- >")
Expand All @@ -37,8 +46,33 @@ def test__upgrades(fmc):
upgrades1.upgrade_package(package_name=package_name)
upgrades1.pushUpgradeFileOnly = True

logging.info(f"Pushing upgrade file to {device_list}")
response = upgrades1.post()
logging.info(response)
wait_for_task(fmc=fmc, task=response["metadata"]["task"], wait_time=60)

# BELOW ARE EXAMPLES OF HOW TO TRIGGER READINESS CHECKS AND ACTUAL UPGRADES
# THIS INCLUDES REBOOTS AND DEPLOYMENTS.

# upgrades1.pushUpgradeFileOnly = False
# upgrades1.readinessCheckOnly = True

# logging.info(f"Triggering readiness checks on {device_list}")
# response = upgrades1.post()
# logging.info(response)
# wait_for_task(fmc=fmc, task=response["metadata"]["task"], wait_time=60)

# upgrades1.readinessCheckOnly = False

# logging.info(f"Triggering REAL UPGRADE on {device_list}")
# response = upgrades1.post()
# logging.info(response)
# wait_for_task(fmc=fmc, task=response["metadata"]["task"], wait_time=60)

# logging.info(f"Upgrade completed. Triggering deployment to devices")
# deployment = fmcapi.DeploymentRequests(fmc=fmc)
# response = deployment.post()
# logging.info(response)
# wait_for_task(fmc=fmc, task=response["metadata"]["task"], wait_time=60)

logging.info("Test UpgradePackages/ApplicableDevices/Upgrades Complete")
2 changes: 1 addition & 1 deletion unit_tests/wait_for_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def wait_for_task(fmc, task, wait_time=10):
task_completed_states = ["Success", "SUCCESS", "COMPLETED"]
task_completed_states = ["Success", "SUCCESS", "COMPLETED", "Deployed"]
try:
status = fmcapi.TaskStatuses(fmc=fmc, id=task["id"])
current_status = status.get()
Expand Down

0 comments on commit 648b8ac

Please sign in to comment.