def yum_updates(self): while self.start: packages = pkg_update_check() data = {} if packages: # Non empty lists are True. data["yum_updates"] = True else: data["yum_updates"] = False data["packages"] = packages self.emit("yum_updates", {"key": "sysinfo:yum_updates", "data": data}) gevent.sleep(1800) # 1800 seconds = 30 mins
def yum_updates(self): while self.start: packages = pkg_update_check() data = {} if packages: # Non empty lists are True. data['yum_updates'] = True else: data['yum_updates'] = False data['packages'] = packages self.emit('yum_updates', { 'key': 'sysinfo:yum_updates', 'data': data }) gevent.sleep(1800) # 1800 seconds = 30 mins
def test_pkg_update_check(self): """ Test pkg_update_check() across distro.id values and consequently different output format of: distro.id = "rockstor" (CentOS) base yum check-update -q -x rock* and: output format of: distro.id = "opensuse-leap" zypper -q list-updates and: distro.id = "opensuse-tumbleweed" same command as for opensuse-leap """ # Mock pkg_changelog to allow for isolated testing of yum_check self.patch_pkg_changelog = patch("system.pkg_mgmt.pkg_changelog") self.mock_pkg_changelog = self.patch_pkg_changelog.start() def fake_pkg_changelog(*args, **kwargs): """ Stubbed out fake pkg_changelog to allow for isolation of caller N.B. currenlty only uses single package test data to simply dict comparisons, ie recersive dict sort othewise required. :param args: :param kwargs: :return: Dict indexed by name=arg[0], installed, available, and description. last 3 are = [] unless arg[1] is not "rockstor" then available has different content. """ pkg_info = {"name": args[0].split(".")[0]} pkg_info["installed"] = "" pkg_info["available"] = "" if args[1] != "rockstor": pkg_info[ "available" ] = "Version and changelog of update not available in openSUSE" pkg_info["description"] = "" return pkg_info self.mock_pkg_changelog.side_effect = fake_pkg_changelog # TODO: We need more example here of un-happy paths # zypper spaces in Repository name Example, out = [ [ "S | Repository | Name | Current Version | Available Version | Arch ", # noqa E501 "--+------------------------+-------------------------+---------------------------------------+---------------------------------------+-------", # noqa E501 "v | Main Update Repository | aaa_base | 84.87+git20180409.04c9dae-lp151.5.3.1 | 84.87+git20180409.04c9dae-lp151.5.6.1 | x86_64", # noqa E501 "", ] ] expected_result = [ [ { "available": "Version and changelog of update not available in openSUSE", "description": "", "name": "aaa_base", "installed": "", } ] ] err = [[""]] rc = [0] dist_id = ["opensuse-tumbleweed"] # # zypper no spaces in Repository name Example, # actual Leap 15.0 but no-space repos also seen in other openSUSE variants. out.append( [ "S | Repository | Name | Current Version | Available Version | Arch", # noqa E501 "--+---------------------------+---------------------------------+---------------------------------------------+---------------------------------------------+-------", # noqa E501 "v | openSUSE-Leap-15.0-Update | NetworkManager | 1.10.6-lp150.4.6.1 | 1.10.6-lp150.4.9.1 | x86_64", # noqa E501 "", ] ) expected_result.append( [ { "available": "Version and changelog of update not available in openSUSE", "description": "", "name": "NetworkManager", "installed": "", } ] ) err.append([""]) rc.append(0) dist_id.append("opensuse-tumbleweed") # # CentOS yum output example, ie one clear line above. out.append( [ "", "epel-release.noarch 7-12 epel", # noqa E501 "", ] ) expected_result.append( [ { "available": "", "description": "", "name": "epel-release", "installed": "", } ] ) err.append([""]) rc.append(100) dist_id.append("rockstor") # # When we have a poorly repo. # '/usr/bin/zypper', '--non-interactive', '-q', 'list-updates'] out.append( [ "", "", "", "", "File 'repomd.xml' from repository 'Rockstor-Testing' is unsigned, continue? [yes/no] (no): no", # noqa E501 "Warning: Skipping repository 'Rockstor-Testing' because of the above error.", # noqa E501 "S | Repository | Name | Current Version | Available Version | Arch ", # noqa E501 "--+------------------------+-------------------------+---------------------------------------+---------------------------------------+-------", # noqa E501 "v | Main Update Repository | aaa_base | 84.87+git20180409.04c9dae-lp151.5.3.1 | 84.87+git20180409.04c9dae-lp151.5.9.1 | x86_64", # noqa E501 "v | Main Update Repository | aaa_base-extras | 84.87+git20180409.04c9dae-lp151.5.3.1 | 84.87+git20180409.04c9dae-lp151.5.9.1 | x86_64", # noqa E501 "v | Main Update Repository | apparmor-parser | 2.12.2-lp151.3.2 | 2.12.3-lp151.4.3.1 | x86_64", # noqa E501 "v | Main Update Repository | bash | 4.4-lp151.9.53 | 4.4-lp151.10.3.1 | x86_64", # noqa E501 "", ] ) expected_result.append( [ { "available": "Version and changelog of update not available in openSUSE", "description": "", "name": "aaa_base", "installed": "", }, { "available": "Version and changelog of update not available in openSUSE", "description": "", "name": "aaa_base-extras", "installed": "", }, { "available": "Version and changelog of update not available in openSUSE", "description": "", "name": "apparmor-parser", "installed": "", }, { "available": "Version and changelog of update not available in openSUSE", "description": "", "name": "bash", "installed": "", }, ] ) err.append( [ "Repository 'Rockstor-Testing' is invalid.", "[Rockstor-Testing|http://updates.rockstor.com:8999/rockstor-testing/leap/15.1] Valid metadata not found at specified URL", # noqa E501 "Some of the repositories have not been refreshed because of an error.", # noqa E501 "", ] ) rc.append(106) dist_id.append("opensuse-leap") # for o, e, r, expected, distro in zip(out, err, rc, expected_result, dist_id): self.mock_run_command.return_value = (o, e, r) self.mock_distro.id.return_value = distro returned = pkg_update_check() self.assertEqual( returned, expected, msg="Un-expected yum_check() result:\n " "returned = ({}).\n " "expected = ({}).".format(returned, expected), )