mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-03-21 18:50:38 +03:00
Use apt-shell for install/remove packages
Add small unit test
This commit is contained in:
parent
d9cad51f52
commit
6c06638138
@ -26,23 +26,20 @@ class rpm:
|
||||
self.packages_for_remove = packages_for_remove
|
||||
|
||||
def apply(self):
|
||||
try:
|
||||
logging.info(slogm('Updating APT-RPM database'))
|
||||
subprocess.check_call(['/usr/bin/apt-get', 'update'])
|
||||
except Exception as exc:
|
||||
logging.info(slogm('Failed to update APT-RPM database: {}'.format(exc)))
|
||||
|
||||
logging.info(slogm('Installing packages: {}. Removing packages {}.'.format(self.packages_for_instsall, self.packages_for_remove)))
|
||||
|
||||
if self.packages_for_remove:
|
||||
self.packages_for_remove = [i + "-" for i in self.packages_for_remove]
|
||||
|
||||
cmd = ['/usr/bin/apt-get', '-y', 'install']
|
||||
cmd.extend(self.packages_for_instsall)
|
||||
cmd.extend(self.packages_for_remove)
|
||||
cmd = 'update\n'
|
||||
cmd += 'install ' + self.packages_for_instsall + '\n'
|
||||
cmd += 'remove ' + self.packages_for_remove + '\n'
|
||||
cmd += 'commit -y\n'
|
||||
|
||||
try:
|
||||
subprocess.check_call(cmd)
|
||||
logging.info(slogm('Installing packages: {}. Removing packages: {}.'.format(self.packages_for_instsall, self.packages_for_remove)))
|
||||
p = subprocess.run(['/usr/bin/apt-shell'], stdout = subprocess.PIPE, stderr = subprocess.PIPE, input = cmd, encoding='utf-8')
|
||||
except Exception as exc:
|
||||
logging.info(slogm('Failed to install/remove packages: {}'.format(exc)))
|
||||
logging.error(slogm('Failed to run /usr/bin/apt-shell: {}'.format(exc)))
|
||||
return
|
||||
|
||||
logging.info(slogm('/usr/bin/apt-shell returned {}'.format(p.returncode)))
|
||||
logging.info(slogm('/usr/bin/apt-shell output:\n{}'.format(p.stdout)))
|
||||
if p.stderr:
|
||||
logging.error(slogm('/usr/bin/apt-shell errors:\n{}'.format(p.stderr)))
|
||||
|
||||
|
@ -28,18 +28,19 @@ class package_applier(applier_frontend):
|
||||
self.package_applier_settings = self.storage.filter_hklm_entries('Software\\BaseALT\\Policies\\Packages%')
|
||||
|
||||
def apply(self):
|
||||
packages_for_install = None
|
||||
packages_for_remove = None
|
||||
packages_for_install = ''
|
||||
packages_for_remove = ''
|
||||
|
||||
for setting in self.package_applier_settings:
|
||||
action = setting.hive_key.rpartition('\\')[2]
|
||||
if action == 'PackagesForInstall':
|
||||
packages_for_install = setting.data.split()
|
||||
packages_for_install = setting.data
|
||||
if action == 'PackagesForRemove':
|
||||
packages_for_remove = setting.data.split()
|
||||
packages_for_remove = setting.data
|
||||
|
||||
r = rpm(packages_for_install, packages_for_remove)
|
||||
r.apply()
|
||||
if packages_for_install or packages_for_remove:
|
||||
r = rpm(packages_for_install, packages_for_remove)
|
||||
r.apply()
|
||||
|
||||
|
||||
class package_applier_user(applier_frontend):
|
||||
|
39
gpoa/test/frontend/appliers/test_packages.py
Normal file
39
gpoa/test/frontend/appliers/test_packages.py
Normal file
@ -0,0 +1,39 @@
|
||||
#
|
||||
# GPOA - GPO Applier for Linux
|
||||
#
|
||||
# Copyright (C) 2019-2020 BaseALT Ltd.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import unittest
|
||||
|
||||
from frontend.appliers.rpm import rpm
|
||||
|
||||
class PackageTestCase(unittest.TestCase):
|
||||
'''
|
||||
Semi-integrational tests for packages installation/removing
|
||||
'''
|
||||
def test_package_not_exist(self):
|
||||
packages_for_install = 'dummy1 dummy2'
|
||||
packages_for_remove = 'dummy3'
|
||||
|
||||
test_rpm = rpm(packages_for_install, packages_for_remove)
|
||||
test_rpm.apply()
|
||||
|
||||
def test_install_remove_same_package(self):
|
||||
packages_for_install = 'gotop'
|
||||
packages_for_remove = 'gotop'
|
||||
|
||||
test_rpm = rpm(packages_for_install, packages_for_remove)
|
||||
test_rpm.apply()
|
Loading…
x
Reference in New Issue
Block a user