Example #1
0
    def run(self):
        """
        Performs install activate operation
        """
        check_ncs6k_release(self.ctx)

        operation_id = None
        if hasattr(self.ctx, 'operation_id'):
            if self.ctx.operation_id != -1:
                self.ctx.info("Using the operation ID: {}".format(self.ctx.operation_id))
                operation_id = self.ctx.operation_id

        if operation_id is None or operation_id == -1:
            tobe_activated = self.get_tobe_activated_pkg_list()
            if not tobe_activated:
                self.ctx.info("Nothing to be activated.")
                return True

        if operation_id is not None and operation_id != -1:
            cmd = 'install activate id {}'.format(operation_id)
        else:
            cmd = 'install activate {}'.format(tobe_activated)

        self.ctx.info("Activate package(s) pending")
        self.ctx.post_status("Activate Package(s) Pending")

        install_activate_deactivate(self.ctx, cmd)

        self.ctx.info("Activate package(s) done")

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)

        update_device_info_udi(self.ctx)
Example #2
0
    def run(self):
        """
        Performs install deactivate operation
        RP/0/RP0/CPU0:Deploy#install deactivate ncs6k-5.2.5.CSCuz65240-1.0.0
        May 27 16:39:31 Install operation 33 started by root:
          install deactivate pkg ncs6k-5.2.5.CSCuz65240-1.0.0
        May 27 16:39:31 Package list:
        May 27 16:39:31     ncs6k-5.2.5.CSCuz65240-1.0.0
        May 27 16:39:36 Install operation will continue in the background
        """
        cmd = get_cmd_for_install_activate_deactivate(self.ctx, self.get_tobe_deactivated_pkg_list,
                                                      cmd_with_package_names='install deactivate {}',
                                                      cmd_with_operation_id='install deactivate id {}')

        if not cmd:
            self.ctx.info("Nothing to be deactivated.")
            return True

        self.ctx.info("Deactivate package(s) pending")
        self.ctx.post_status("Deactivate Package(s) Pending")

        install_activate_deactivate(self.ctx, cmd)

        self.ctx.info("Deactivate package(s) done")

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #3
0
    def run(self):
        packages = self.ctx.software_packages
        if packages is None:
            self.ctx.error("No package list provided")
            return

        pkgs = SoftwarePackage.from_package_list(packages)

        admin_installed_inact = SoftwarePackage.from_show_cmd(
            send_admin_cmd(self.ctx, "show install inactive"))
        installed_inact = SoftwarePackage.from_show_cmd(
            self.ctx.send("show install inactive"))

        installed_inact.update(admin_installed_inact)
        packages_to_remove = pkgs & installed_inact

        if not packages_to_remove:
            self.ctx.warning("Packages already removed. Nothing to be removed")
            return

        to_remove = " ".join(map(str, packages_to_remove))

        cmd = 'install remove {}'.format(to_remove)

        self.ctx.info("Remove Package(s) Pending")
        self.ctx.post_status("Remove Package(s) Pending")

        output = self.ctx.send(cmd, timeout=600)
        observe_install_add_remove(self.ctx, output)

        self.ctx.info("Package(s) Removed Successfully")

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #4
0
    def run(self):

        host = None
        try:
            host = self.ctx.get_host
        except AttributeError:
            self.ctx.error("No host selected.")

        if host is None:
            self.ctx.error("No host selected.")

        log_and_post_status(self.ctx,
                            "Run migration script to extract the image and boot files and set boot mode in device")

        self._run_migration_script()

        log_and_post_status(self.ctx, "Reload device to boot ASR9K-X64 image.")
        self._reload_all()

        run_additional_custom_commands(self.ctx, {"show platform"})

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)

        update_device_info_udi(self.ctx)

        return True
Example #5
0
    def run(self):

        cmd = 'install remove inactive all'

        self.ctx.info("Remove All Inactive Package(s) Pending")
        self.ctx.post_status("Remove All Inactive Package(s) Pending")

        observe_install_remove_all(self.ctx, cmd, self.ctx.prompt)

        self.ctx.info("Remove All Inactive Package(s) Successfully")

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #6
0
    def run(self):
        """
        It performs commit operation
        RP/0/RP0/CPU0:Deploy#install commit
        May 27 16:34:04 Install operation 32 started by root:
          install commit
        May 27 16:34:05 Install operation will continue in the background

        RP/0/RP0/CPU0:Deploy#May 27 16:34:11 Install operation 32 finished successfully
        """
        cmd = "install commit"
        output = self.ctx.send(cmd)
        result = re.search('Install operation (\d+)', output)
        if result:
            op_id = result.group(1)
            watch_operation(self.ctx, op_id)
        else:
            log_install_errors(self.ctx, output)
            self.ctx.error("Operation ID not found.")
            return

        failed_oper = r'Install operation {} aborted'.format(op_id)
        success_oper = r'Install operation (\d+) finished successfully'

        # Not sure if this is still the message on NCS6K
        completed_with_failure = 'Install operation (\d+) completed with failure'

        cmd = "show install log {} detail".format(op_id)
        output = self.ctx.send(cmd)

        if re.search(failed_oper, output):
            log_install_errors(self.ctx, output)
            self.ctx.error("Install operation failed.")
            return

        if re.search(completed_with_failure, output):
            log_install_errors(self.ctx, output)
            self.ctx.info(
                "Completed with failure but failure was after Point of No Return."
            )
        elif re.search(success_oper, output):
            self.ctx.info("Operation {} finished successfully.".format(op_id))

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #7
0
    def run(self):
        check_ncs6k_release(self.ctx)

        server_repository_url = self.ctx.server_repository_url
        if server_repository_url is None:
            self.ctx.error("No repository provided")
            return

        packages = self.ctx.software_packages
        if packages is None:
            self.ctx.error("No package list provided")
            return

        has_tar = False

        if self.ctx.family == 'NCS6K':
            s_packages = " ".join([
                package for package in packages
                if ('iso' in package or 'pkg' in package or 'smu' in package
                    or 'tar' in package)
            ])
        else:
            s_packages = " ".join([
                package for package in packages
                if ('rpm' in package or 'iso' in package or 'tar' in package)
            ])

        if 'tar' in s_packages:
            has_tar = True

        if not s_packages:
            self.ctx.error(
                "None of the selected package(s) has an acceptable file extension."
            )

        self.ctx.info("Add Package(s) Pending")
        self.ctx.post_status("Add Package(s) Pending")

        self.install_add(server_repository_url, s_packages, has_tar=has_tar)

        self.ctx.info("Package(s) Added Successfully")

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #8
0
    def run(self):
        """
        It performs commit operation
        RP/0/RP0/CPU0:Deploy#install commit
        May 27 16:34:04 Install operation 32 started by root:
          install commit
        May 27 16:34:05 Install operation will continue in the background

        RP/0/RP0/CPU0:Deploy#May 27 16:34:11 Install operation 32 finished successfully
        """
        cmd = "install commit"
        output = self.ctx.send(cmd)
        result = re.search(r'Install operation (\d+)', output)
        if result:
            op_id = result.group(1)
            watch_operation(self.ctx, op_id)
        else:
            log_install_errors(self.ctx, output)
            self.ctx.error("Operation ID not found.")
            return

        failed_oper = r'Install operation {} aborted'.format(op_id)
        success_oper = r'Install operation (\d+) finished successfully'

        # Not sure if this is still the message on NCS6K
        completed_with_failure = r'Install operation (\d+) completed with failure'

        cmd = "show install log {} detail".format(op_id)
        output = self.ctx.send(cmd)

        if re.search(failed_oper, output):
            log_install_errors(self.ctx, output)
            self.ctx.error("Install operation failed.")
            return

        if re.search(completed_with_failure, output):
            log_install_errors(self.ctx, output)
            self.ctx.info("Completed with failure but failure was after Point of No Return.")
        elif re.search(success_oper, output):
            self.ctx.info("Operation {} finished successfully.".format(op_id))

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #9
0
    def run(self):
        """
        Performs install deactivate operation
        RP/0/RP0/CPU0:Deploy#install deactivate ncs6k-5.2.5.CSCuz65240-1.0.0
        May 27 16:39:31 Install operation 33 started by root:
          install deactivate pkg ncs6k-5.2.5.CSCuz65240-1.0.0
        May 27 16:39:31 Package list:
        May 27 16:39:31     ncs6k-5.2.5.CSCuz65240-1.0.0
        May 27 16:39:36 Install operation will continue in the background
        """
        check_ncs6k_release(self.ctx)

        operation_id = None
        if hasattr(self.ctx, 'operation_id'):
            if self.ctx.operation_id != -1:
                self.ctx.info("Using the operation ID: {}".format(
                    self.ctx.operation_id))
                operation_id = self.ctx.operation_id

        if operation_id is None or operation_id == -1:
            tobe_deactivated = self.get_tobe_deactivated_pkg_list()
            if not tobe_deactivated:
                self.ctx.info("Nothing to be deactivated.")
                return True

        if operation_id is not None and operation_id != -1:
            cmd = 'install deactivate id {}'.format(operation_id)
        else:
            cmd = 'install deactivate {}'.format(tobe_deactivated)

        self.ctx.info("Deactivate package(s) pending")
        self.ctx.post_status("Deactivate Package(s) Pending")

        install_activate_deactivate(self.ctx, cmd)

        self.ctx.info("Deactivate package(s) done")

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #10
0
    def run(self):
        server_repository_url = self.ctx.server_repository_url
        if server_repository_url is None:
            self.ctx.error("No repository provided")
            return

        packages = self.ctx.software_packages
        if packages is None:
            self.ctx.error("No package list provided")
            return

        has_tar = False

        if self.ctx.family == 'NCS4K':
            s_packages = " ".join([package for package in packages
                                   if (any(s in package for s in ['iso', 'pkg', 'smu', 'tar']))])
        elif self.ctx.family == 'NCS6K':
            # Pre-6.3.1 supports '.smu', 6.3.1 and later supports '.rpm'
            s_packages = " ".join([package for package in packages
                                   if (any(s in package for s in ['iso', 'pkg', 'smu', 'tar', 'rpm']))])
        else:
            s_packages = " ".join([package for package in packages
                                   if (any(s in package for s in ['iso', 'tar', 'rpm']))])

        if 'tar' in s_packages:
            has_tar = True

        if not s_packages:
            self.ctx.error("None of the selected package(s) has an acceptable file extension.")

        self.ctx.info("Add Package(s) Pending")
        self.ctx.post_status("Add Package(s) Pending")

        self.install_add(server_repository_url, s_packages, has_tar=has_tar)

        self.ctx.info("Package(s) Added Successfully")

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #11
0
    def run(self):
        packages = self.ctx.software_packages
        if packages is None:
            self.ctx.error("No package list provided")
            return

        # If a wide card character is detected, only the first element
        # in the list is considered valid.
        if any('*' in package for package in packages):
            to_remove = packages[0]
        else:
            pkgs = SoftwarePackage.from_package_list(packages)

            admin_installed_inact = SoftwarePackage.from_show_cmd(send_admin_cmd(self.ctx, "show install inactive"))
            installed_inact = SoftwarePackage.from_show_cmd(self.ctx.send("show install inactive"))

            installed_inact.update(admin_installed_inact)
            packages_to_remove = pkgs & installed_inact

            if not packages_to_remove:
                self.ctx.warning("Packages already removed. Nothing to be removed")
                return

            to_remove = " ".join(map(str, packages_to_remove))

        cmd = 'install remove {}'.format(to_remove)

        self.ctx.info("Remove Package(s) Pending")
        self.ctx.post_status("Remove Package(s) Pending")

        output = self.ctx.send(cmd, timeout=600)
        observe_install_add_remove(self.ctx, output)

        self.ctx.info("Package(s) Removed Successfully")

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #12
0
    def run(self):
        host = None
        try:
            host = self.ctx.get_host
        except AttributeError:
            self.ctx.error("No host selected.")

        if host is None:
            self.ctx.error("No host selected.")

        log_and_post_status(
            self.ctx,
            "Run migration script to extract the image and boot files and set boot mode in device"
        )
        self._run_migration_script()

        log_and_post_status(self.ctx, "Reload device to boot eXR")
        self._reload_all(host)

        try:
            self.ctx.custom_commands = ["show platform"]
            cmd_capture_plugin = CmdCapturePlugin(self.ctx)
            cmd_capture_plugin.run()
        except PluginError as e:
            log_and_post_status(
                self.ctx,
                "Failed to capture 'show platform' - ({}): {}".format(
                    e.errno, e.strerror))

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)

        update_device_info_udi(self.ctx)

        return True
Example #13
0
    def run(self):

        log_and_post_status(self.ctx,
                            "Waiting for all nodes to come to FINAL Band.")
        if not wait_for_final_band(self.ctx):
            log_and_post_status(
                self.ctx,
                "Warning: Not all nodes are in FINAL Band after 25 minutes.")

        try:
            self.ctx.custom_commands = ["show running-config"]
            cmd_capture_plugin = CmdCapturePlugin(self.ctx)
            cmd_capture_plugin.run()
        except PluginError as e:
            log_and_post_status(
                self.ctx,
                "Failed to capture 'show running-config' - ({}): {}".format(
                    e.errno, e.strerror))

        log_and_post_status(self.ctx,
                            "Loading the migrated Calvados configuration.")
        self.ctx.send("admin")
        self._copy_file_from_eusb_to_harddisk(FINAL_CAL_CONFIG)
        self._load_admin_config(FINAL_CAL_CONFIG)

        try:
            # This is still in admin mode
            output = self.ctx.send("show running-config", timeout=2200)
            file_name = self.ctx.save_to_file("admin show running-config",
                                              output)
            if file_name is None:
                log_and_post_status(
                    self.ctx, "Unable to save '{}' output to file: {}".format(
                        "admin show running-config", file_name))
            else:
                log_and_post_status(
                    self.ctx,
                    "Output of '{}' command saved to file: {}".format(
                        "admin show running-config", file_name))
        except Exception as e:
            log_and_post_status(
                self.ctx,
                str(type(e)) +
                " when trying to capture 'admin show running-config'.")

        self.ctx.send("exit")

        self._check_fpds_for_upgrade()

        try:
            self.ctx.custom_commands = ["show platform"]
            cmd_capture_plugin = CmdCapturePlugin(self.ctx)
            cmd_capture_plugin.run()
        except PluginError as e:
            log_and_post_status(
                self.ctx,
                "Failed to capture 'show platform' - ({}): {}".format(
                    e.errno, e.strerror))

        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)
Example #14
0
    def run(self):

        need_reload = False

        # XR ddts CSCvb67386 workaround
        # if cbc only or power module only, then do not reload
        avoid_reload = False

        self.ctx.info("FPD-Upgrade Pending")
        self.ctx.post_status("FPD-Upgrade Pending")

        if not fpd_package_installed(self.ctx):
            self.ctx.error("No FPD package is active on device. "
                           "Please install and activate the FPD package on device first.")
            return False

        fpd_location = self.ctx.load_job_data('fpd_location')[0]
        fpd_type = self.ctx.load_job_data('fpd_type')[0]

        self.ctx.info("fpd_location = {}".format(fpd_location))
        self.ctx.info("fpd_type = {}".format(fpd_type))

        if not fpd_location:
            fpd_location = 'all'
        if not fpd_type:
            fpd_type = 'all'

        # case 1: both fpd_location and fpd_type are none.
        # case 2: only fpd_location is specified
        # case 3: only fpd_type is specified
        # case 4: both fpd_location and fpd_type are specified

        locations = fpd_locations(self.ctx)
        self.ctx.info("FPD Location to be upgraded = {}".format(locations))

        upgd_result = True
        begin = time.time()
        for location in locations:
            if location == fpd_location or fpd_location == 'all':
                if fpd_needs_upgd(self.ctx, location, fpd_type):
                    need_reload = True
                    if not hw_fpd_upgd(self.ctx, location, fpd_type):
                        upgd_result = False
            else:
                continue

        if not need_reload:
            self.ctx.info("All FPD devices are current. Nothing to be upgraded.")
            return True

        if 'cbc' in fpd_type or '/PS' in 'fpd_location':
            avoid_reload = True

        if fpd_location == 'all' and fpd_type == 'all':
            avoid_reload = cbc_pwr_only(self.ctx)

        if not avoid_reload:
            elapsed = time.time() - begin
            self.ctx.info("Overall fpd upgrade time: {} minute(s) {:.0f} second(s)".format(elapsed // 60, elapsed % 60))

            self.ctx.info("Reloading the host")

            if not hw_fpd_reload(self.ctx, fpd_location):
                self.ctx.warning("Encountered error when attempting to reload device.")

            self.ctx.info("Wait for the host reload to complete")
            success = wait_for_reload(self.ctx)
            if not success:
                self.ctx.error("Reload or boot failure")
                return False

        self.ctx.info("Refreshing package and inventory information")
        self.ctx.post_status("Refreshing package and inventory information")
        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)

        update_device_info_udi(self.ctx)

        if upgd_result:
            for location in locations:
                if location == fpd_location or fpd_location == 'all':
                    if not fpd_check_status(self.ctx, location, fpd_type):
                        upgd_result = False
                else:
                    continue

        if upgd_result:
            self.ctx.info("FPD-Upgrade Successfully")
            return True
        else:
            self.ctx.error("FPD-Upgrade completed but the status of one or more nodes is not current")
            return False
Example #15
0
    def run(self):

        self.ctx.info("FPD-Upgrade Pending")
        self.ctx.post_status("FPD-Upgrade Pending")

        fpd_location = self.ctx.load_job_data('fpd_location')[0]
        fpd_type = self.ctx.load_job_data('fpd_type')[0]

        self.ctx.info("fpd_location = {}".format(fpd_location))
        self.ctx.info("fpd_type = {}".format(fpd_type))

        # case 1: both fpd_location and fpd_type are none.
        if not fpd_location and not fpd_type:
            fpd_location = 'all'
            fpd_type = 'all'
        # case 2: only fpd_location is specified
        # case 3: only fpd_type is specified
        # case 4: both fpd_location and fpd_type are specified

        if fpd_is_current(self.ctx, fpd_location, fpd_type):
            self.ctx.info("All FPD devices are CURRENT. Nothing to be upgraded.")
            return True

        upgd_locations = fpd_needs_upgd(self.ctx, fpd_location, fpd_type)
        self.ctx.info("locations to be upgraded = {}".format(upgd_locations))
        if upgd_locations:
            if fpd_location == 'all' and fpd_type == 'all':
                if not hw_fpd_upgd(self.ctx, fpd_location, fpd_type):
                    self.ctx.error("Fail to issue {}".format('upgrade hw-module location all fpd all'))
                    return
                wait_for_fpd_upgd(self.ctx, fpd_location, fpd_type)
            elif fpd_location and not fpd_type:
                type = 'all'
                if not hw_fpd_upgd(self.ctx, fpd_location, type):
                    cmd = 'upgrade hw-module location ' + fpd_location + ' fpd ' + type
                    self.ctx.error("Fail to issue {}".format(cmd))
                    return
                wait_for_fpd_upgd(self.ctx, fpd_location, type)
            elif not fpd_location and fpd_type:
                for location in upgd_locations:
                    if not hw_fpd_upgd(self.ctx, location, fpd_type):
                        cmd = 'upgrade hw-module location ' + location + ' fpd ' + fpd_type
                        self.ctx.error("Fail to issue {}".format(cmd))
                        return
                    wait_for_fpd_upgd(self.ctx, location, fpd_type)
                    time.sleep(30)  # CLI may not work if issuing too quickly
            else:
                if not hw_fpd_upgd(self.ctx, fpd_location, fpd_type):
                    cmd = 'upgrade hw-module location ' + fpd_location + ' fpd ' + fpd_type
                    self.ctx.error("Fail to issue {}".format(cmd))
                    return
                wait_for_fpd_upgd(self.ctx, fpd_location, fpd_type)

        if not fpd_location and fpd_type:
            # check if RP0 / RP1 is to be reloaded
            location = None
            if upgd_locations:
                for location in upgd_locations:
                    if 'RP' in location or 'RSP' in location:
                        location = 'all'
                        break

            if location == 'all':
                if not hw_fpd_reload(self.ctx, location):
                    cmd = 'admin hw-module location ' + location + ' reload'
                    self.ctx.error("Fail to issue {}".format(cmd))
                    return
            else:
                if upgd_locations:
                    for location in upgd_locations:
                        if not hw_fpd_reload(self.ctx, location):
                            cmd = 'admin hw-module location ' + location + ' reload'
                            self.ctx.error("Fail to issue {}".format(cmd))
                            return
                        time.sleep(10)
        else:
            if not hw_fpd_reload(self.ctx, fpd_location):
                cmd = 'admin hw-module location ' + fpd_location + ' reload'
                self.ctx.error("Fail to issue {}".format(cmd))
                return

        success = wait_for_reload(self.ctx)
        if not success:
            self.ctx.error("Reload or boot failure")
            return

        self.ctx.info("Refreshing package and inventory information")
        self.ctx.post_status("Refreshing package and inventory information")
        # Refresh package and inventory information
        get_package(self.ctx)
        get_inventory(self.ctx)

        update_device_info_udi(self.ctx)

        if fpd_check_status(self.ctx, fpd_location, fpd_type):
            self.ctx.info("FPD-Upgrade Successfully")
            return True
        else:
            self.ctx.error("FPD-Upgrade Completed but the status of one or more nodes is not Current or N/A")
            return False