diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml new file mode 100644 index 00000000..3045c629 --- /dev/null +++ b/.github/workflows/run_tests.yml @@ -0,0 +1,48 @@ +name: GISCExFabtools + +on: + push: + branches: [ git_clone_branch ] + pull_request: + branches: [ git_clone_branch ] + +jobs: + run-tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["2.7", "3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + if: matrix.python-version != '2.7' + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Python 2 + if: matrix.python-version == '2.7' + run: | + sudo apt update + sudo apt install python2 python-pip + sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 + sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2 + printf '1\n' | sudo update-alternatives --config python + cd /usr/bin + sudo ln -s /usr/bin/pip2 ./pip + + - name: Upgrade pip + run: | + pip install --upgrade pip setuptools wheel + + - name: Install package + run: | + pip install pytest + pip install mock + pip install -e . + + - name: Run test + run: | + python -m unittest discover -v \ No newline at end of file diff --git a/fabtools/openvz/contextmanager.py b/fabtools/openvz/contextmanager.py index 3b199632..0d026101 100644 --- a/fabtools/openvz/contextmanager.py +++ b/fabtools/openvz/contextmanager.py @@ -158,8 +158,8 @@ def put_guest(self, local_path, remote_path, use_sudo, mirror_local_mode, # Handle modes if necessary if (local_is_path and mirror_local_mode) or (mode is not None): lmode = os.stat(local_path).st_mode if mirror_local_mode else mode - lmode = lmode & 07777 - rmode = rattrs.st_mode & 07777 + lmode = lmode & 0o7777 + rmode = rattrs.st_mode & 0o7777 if lmode != rmode: with hide('everything'): sudo('chmod %o \"%s\"' % (lmode, remote_path)) diff --git a/fabtools/require/files.py b/fabtools/require/files.py index a4443868..2b33cab0 100644 --- a/fabtools/require/files.py +++ b/fabtools/require/files.py @@ -9,7 +9,7 @@ from pipes import quote from tempfile import mkstemp -from urlparse import urlparse +from six.moves.urllib_parse import urlparse import hashlib import os @@ -191,7 +191,7 @@ def file(path=None, contents=None, source=None, url=None, md5=None, # Ensure correct mode if use_sudo and mode is None: - mode = oct(0666 & ~int(umask(use_sudo=True), base=8)) + mode = oct(0o666 & ~int(umask(use_sudo=True), base=8)) if mode and _mode(path, use_sudo) != mode: func('chmod %(mode)s "%(path)s"' % locals()) diff --git a/fabtools/tests/test_files.py b/fabtools/tests/test_files.py index 3cc20417..289d105b 100644 --- a/fabtools/tests/test_files.py +++ b/fabtools/tests/test_files.py @@ -34,31 +34,31 @@ def test_verify_remote_true(self, is_file, md5sum, put, umask, owner, mode): used to work out whether the file is different. """ is_file.return_value = True - md5sum.return_value = hashlib.md5('This is a test').hexdigest() + md5sum.return_value = hashlib.md5('This is a test'.encode()).hexdigest() self._file(contents='This is a test', verify_remote=True) self.assertTrue(is_file.called) self.assertTrue(md5sum.called) def test_temp_dir(self, is_file, md5sum, put, umask, owner, mode): owner.return_value = 'root' - umask.return_value = '0002' - mode.return_value = '0664' + umask.return_value = '{}'.format(oct(eval('0o002'))) + mode.return_value = '{}'.format(oct(eval('0o664'))) from fabtools import require require.file('/var/tmp/foo', source=__file__, use_sudo=True, temp_dir='/somewhere') put.assert_called_with(__file__, '/var/tmp/foo', use_sudo=True, temp_dir='/somewhere') def test_home_as_temp_dir(self, is_file, md5sum, put, umask, owner, mode): owner.return_value = 'root' - umask.return_value = '0002' - mode.return_value = '0664' + umask.return_value = '{}'.format(oct(eval('0o002'))) + mode.return_value = '{}'.format(oct(eval('0o664'))) from fabtools import require require.file('/var/tmp/foo', source=__file__, use_sudo=True, temp_dir='') put.assert_called_with(__file__, '/var/tmp/foo', use_sudo=True, temp_dir='') def test_default_temp_dir(self, is_file, md5sum, put, umask, owner, mode): owner.return_value = 'root' - umask.return_value = '0002' - mode.return_value = '0664' + umask.return_value = '{}'.format(oct(eval('0o002'))) + mode.return_value = '{}'.format(oct(eval('0o664'))) from fabtools import require require.file('/var/tmp/foo', source=__file__, use_sudo=True) put.assert_called_with(__file__, '/var/tmp/foo', use_sudo=True, temp_dir='/tmp') diff --git a/setup.py b/setup.py index 7c9258c6..d3310efa 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ def run_tests(self): url='http://fabtools.readthedocs.org/', license='BSD', install_requires=[ - "fabric>=1.7.0", + "fabric>=1.7.0,<2.0", ], setup_requires=[], tests_require=[