Merge pull request #49875 from dwoz/win_spm_tests

Add spm tests to Windows suite
This commit is contained in:
Daniel Wozniak 2018-10-05 11:13:06 -07:00 committed by GitHub
commit eee82d3a87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 3 deletions

View file

@ -95,6 +95,8 @@ class SPMClient(object):
self.files_prov = self.opts.get('spm_files_provider', 'local')
self._prep_pkgdb()
self._prep_pkgfiles()
self.db_conn = None
self.files_conn = None
self._init()
def _prep_pkgdb(self):
@ -104,8 +106,14 @@ class SPMClient(object):
self.pkgfiles = salt.loader.pkgfiles(self.opts)
def _init(self):
self.db_conn = self._pkgdb_fun('init')
self.files_conn = self._pkgfiles_fun('init')
if not self.db_conn:
self.db_conn = self._pkgdb_fun('init')
if not self.files_conn:
self.files_conn = self._pkgfiles_fun('init')
def _close(self):
if self.db_conn:
self.db_conn.close()
def run(self, args):
'''
@ -133,6 +141,8 @@ class SPMClient(object):
self._info(args)
elif command == 'list':
self._list(args)
elif command == 'close':
self._close()
else:
raise SPMInvocationError('Invalid command \'{0}\''.format(command))
except SPMException as exc:
@ -249,7 +259,7 @@ class SPMClient(object):
if pkg.endswith('.spm'):
if self._pkgfiles_fun('path_exists', pkg):
comps = pkg.split('-')
comps = '-'.join(comps[:-2]).split('/')
comps = os.path.split('-'.join(comps[:-2]))
pkg_name = comps[-1]
formula_tar = tarfile.open(pkg, 'r:bz2')
@ -265,6 +275,7 @@ class SPMClient(object):
to_install.extend(to_)
optional.extend(op_)
recommended.extend(re_)
formula_tar.close()
else:
raise SPMInvocationError('Package file {0} not found'.format(pkg))
else:
@ -901,6 +912,7 @@ class SPMClient(object):
formula_def = salt.utils.yaml.safe_load(formula_ref)
self.ui.status(self._get_info(formula_def))
formula_tar.close()
def _info(self, args):
'''

View file

@ -73,7 +73,9 @@ def info(package, conn=None):
'''
List info for a package
'''
close = False
if conn is None:
close = True
conn = init()
fields = (
@ -94,6 +96,8 @@ def info(package, conn=None):
(package, )
)
row = data.fetchone()
if close:
conn.close()
if not row:
return None
@ -107,7 +111,9 @@ def list_packages(conn=None):
'''
List files for an installed package
'''
close = False
if conn is None:
close = True
conn = init()
ret = []
@ -115,6 +121,8 @@ def list_packages(conn=None):
for pkg in data.fetchall():
ret.append(pkg)
if close:
conn.close()
return ret
@ -122,17 +130,23 @@ def list_files(package, conn=None):
'''
List files for an installed package
'''
close = False
if conn is None:
close = True
conn = init()
data = conn.execute('SELECT package FROM packages WHERE package=?', (package, ))
if not data.fetchone():
if close:
conn.close()
return None
ret = []
data = conn.execute('SELECT path, sum FROM files WHERE package=?', (package, ))
for file_ in data.fetchall():
ret.append(file_)
if close:
conn.close()
return ret
@ -141,7 +155,9 @@ def register_pkg(name, formula_def, conn=None):
'''
Register a package in the package database
'''
close = False
if conn is None:
close = True
conn = init()
conn.execute('INSERT INTO packages VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', (
@ -157,13 +173,17 @@ def register_pkg(name, formula_def, conn=None):
formula_def['summary'],
formula_def['description'],
))
if close:
conn.close()
def register_file(name, member, path, digest='', conn=None):
'''
Register a file in the package database
'''
close = False
if conn is None:
close = True
conn = init()
conn.execute('INSERT INTO files VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', (
@ -180,6 +200,8 @@ def register_file(name, member, path, digest='', conn=None):
member.gname,
member.mtime
))
if close:
conn.close()
def unregister_pkg(name, conn=None):
@ -196,10 +218,14 @@ def unregister_file(path, pkg=None, conn=None): # pylint: disable=W0612
'''
Unregister a file from the package database
'''
close = False
if conn is None:
close = True
conn = init()
conn.execute('DELETE FROM files WHERE path=?', (path, ))
if close:
conn.close()
def db_exists(db_):

View file

@ -766,6 +766,7 @@ class SPMCase(TestCase, AdaptedConfigurationTestCaseMixin):
def run_spm(self, cmd, config, arg=None):
client = self._spm_client(config)
spm_cmd = client.run([cmd, arg])
client._close()
return self.ui._status

View file

@ -77,6 +77,12 @@ integration.shell.test_arguments
integration.shell.test_auth
integration.shell.test_call
integration.shell.test_cloud
integration.spm.test_build
integration.spm.test_files
integration.spm.test_info
integration.spm.test_install
integration.spm.test_remove
integration.spm.test_repo
integration.states.test_host
integration.states.test_pip_state
integration.states.test_pkg