Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit test on Python 3.8 #56031

Merged
merged 6 commits into from
Apr 24, 2020
Merged

Fix unit test on Python 3.8 #56031

merged 6 commits into from
Apr 24, 2020

Commits on Apr 24, 2020

  1. Fix deprecation warnings for imports from collections

    DeprecationWarning: Using or importing the ABCs from `collections`
    instead of from `collections.abc` is deprecated since Python 3.3, and in
    3.9 it will stop working.
    
    Therefore try to import the abstract base classes from `collections.abc`
    before falling back to `collections`.
    
    Signed-off-by: Benjamin Drung <[email protected]>
    bdrung committed Apr 24, 2020
    Configuration menu
    Copy the full SHA
    420bbe8 View commit details
    Browse the repository at this point in the history
  2. Support distro.linux_distribution

    Salt fails on Python 3.8:
    
    ```
    ======================================================================
    ERROR: unit.grains.test_core (unittest.loader._FailedTest)
    ----------------------------------------------------------------------
    ImportError: Failed to import test module: unit.grains.test_core
    Traceback (most recent call last):
      File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
        module = self._get_module_from_name(name)
      File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
        __import__(name)
      File "tests/unit/grains/test_core.py", line 37, in <module>
        import salt.grains.core as core
      File "salt/grains/core.py", line 40, in <module>
        from platform import _supported_dists
    ImportError: cannot import name '_supported_dists' from 'platform' (/usr/lib/python3.8/platform.py)
    ```
    
    So only try to import `_supported_dists` from `platform` for Python <=
    3.7. Otherwise rely on the external `distro` module to  not need any
    special handling.
    
    Addresses parts of saltstack#55835
    Signed-off-by: Benjamin Drung <[email protected]>
    bdrung committed Apr 24, 2020
    Configuration menu
    Copy the full SHA
    501a843 View commit details
    Browse the repository at this point in the history
  3. Fix RuntimeError: dictionary keys changed during iteration

    The following unit tests fail on Python 3.8:
    
    ```
    ======================================================================
    ERROR: test_state_config (unit.renderers.test_stateconf.StateConfigRendererTestCase)
    [CPU:0.0%|MEM:56.6%]
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/<<PKGBUILDDIR>>/tests/unit/renderers/test_stateconf.py", line 74, in test_state_config
        result = self._render_sls('''
      File "/<<PKGBUILDDIR>>/tests/unit/renderers/test_stateconf.py", line 66, in _render_sls
        return self._renderers['stateconf'](
      File "/<<PKGBUILDDIR>>/salt/renderers/stateconf.py", line 227, in render
        for k in six.iterkeys(tmplctx):  # iterate over a copy of keys
    RuntimeError: dictionary keys changed during iteration
    
    ======================================================================
    ERROR: test_apply_cloud_providers_config_extend (unit.test_config.ConfigTestCase)
    [CPU:0.0%|MEM:56.6%]
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/<<PKGBUILDDIR>>/tests/unit/test_config.py", line 1243, in test_apply_cloud_providers_config_extend
        salt.config.apply_cloud_providers_config(
      File "/<<PKGBUILDDIR>>/salt/config/__init__.py", line 3196, in apply_cloud_providers_config
        for driver, details in six.iteritems(entries):
    RuntimeError: dictionary keys changed during iteration
    
    ======================================================================
    ERROR: test_apply_cloud_providers_config_extend_multiple (unit.test_config.ConfigTestCase)
    [CPU:0.0%|MEM:56.6%]
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/<<PKGBUILDDIR>>/tests/unit/test_config.py", line 1334, in test_apply_cloud_providers_config_extend_multiple
        self.assertEqual(ret, salt.config.apply_cloud_providers_config(overrides, defaults=DEFAULT))
      File "/<<PKGBUILDDIR>>/salt/config/__init__.py", line 3196, in apply_cloud_providers_config
        for driver, details in six.iteritems(entries):
    RuntimeError: dictionary keys changed during iteration
    
    ======================================================================
    ```
    
    Replace the affected for loop of the first case by a dictionary
    comprehension to construct the modified dictionary. For the remaining
    cases, switch from `iteritems` to `iterkeys`, since the dictionary
    values will be modified.
    
    Signed-off-by: Benjamin Drung <[email protected]>
    bdrung committed Apr 24, 2020
    Configuration menu
    Copy the full SHA
    beaef55 View commit details
    Browse the repository at this point in the history
  4. Fix unit.modules.test_virt.VirtTestCase.test_update

    The test case `unit.modules.test_virt.VirtTestCase.test_update` fails on
    Ubuntu 20.04 with Python 3.8:
    
    ```
    ======================================================================
    FAIL: test_update (unit.modules.test_virt.VirtTestCase)
    [CPU:0.0%|MEM:17.0%]
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "tests/unit/modules/test_virt.py", line 1313, in test_update
        self.assertEqual({
    AssertionError: {'definition': False, 'disk': {'attached': [], 'detached[49 chars] []}} != {'definition': True, 'disk': {'attached': [], 'detached'[74 chars]True}
    + {'cpu': True,
    - {'definition': False,
    ? ^              ^^^^
    
    +  'definition': True,
    ? ^              ^^^
    
       'disk': {'attached': [], 'detached': []},
    -  'interface': {'attached': [], 'detached': []}}
    ?                                               ^
    
    +  'interface': {'attached': [], 'detached': []},
    ?                                               ^
    
    +  'mem': True}
    
    ======================================================================
    ```
    
    `virt.update` falsely detects a change to the graphics setting in the
    "no diff case". The old XML part specifies:
    
    ```xml
    <graphics type="spice" port="5900" autoport="yes" listen="127.0.0.1">
        <listen type="address" address="127.0.0.1" />
    </graphics>
    ```
    
    The newly generated XML misses the port setting:
    
    ```xml
    <graphics type="spice" listen="127.0.0.1" autoport="yes">
        <listen type="address" address="127.0.0.1" />
    </graphics>
    ```
    
    So adjust the initial XML file of the template, because setting the port
    to the default 5900, will change `autoport` to `no`.
    
    Signed-off-by: Benjamin Drung <[email protected]>
    bdrung committed Apr 24, 2020
    Configuration menu
    Copy the full SHA
    f793484 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    01fb8fc View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    26d3a77 View commit details
    Browse the repository at this point in the history