<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/openstack/nova.git/nova/tests/unit/virt/disk, branch master</title>
<subtitle>opendev.org: openstack/nova.git
</subtitle>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/'/>
<entry>
<title>Add mock to avoid loading guestfs in unit test</title>
<updated>2023-01-05T01:51:32+00:00</updated>
<author>
<name>melanie witt</name>
<email>melwittt@gmail.com</email>
</author>
<published>2022-10-27T01:43:55+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=ecb11043e9c2a798950d63b55cd08684b1d77c4a'/>
<id>ecb11043e9c2a798950d63b55cd08684b1d77c4a</id>
<content type='text'>
We recently discovered that when the perfect conditions are present
where:

  * libguestfs-dev/el and guestfs python bindings are installed

and

  * unit tests are not being run in a venv or guestfs python bindings
    are installed in the tox venv

the test will end up loading the guestfs module and try to call the
real guestfs and possibly libvirt and fail because of it.

Our unit tests shouldn't be loading modules like guestfs, so this adds
proper mocking to the test along with a poison fixture that will
prevent future accidental imports of such modules.

Closes-Bug: #1994913

Change-Id: I676ee1fd33cf053681a07448759c28f0f2ad79d1
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We recently discovered that when the perfect conditions are present
where:

  * libguestfs-dev/el and guestfs python bindings are installed

and

  * unit tests are not being run in a venv or guestfs python bindings
    are installed in the tox venv

the test will end up loading the guestfs module and try to call the
real guestfs and possibly libvirt and fail because of it.

Our unit tests shouldn't be loading modules like guestfs, so this adds
proper mocking to the test along with a poison fixture that will
prevent future accidental imports of such modules.

Closes-Bug: #1994913

Change-Id: I676ee1fd33cf053681a07448759c28f0f2ad79d1
</pre>
</div>
</content>
</entry>
<entry>
<title>Use unittest.mock instead of third party mock</title>
<updated>2022-08-01T15:46:26+00:00</updated>
<author>
<name>Stephen Finucane</name>
<email>stephenfin@redhat.com</email>
</author>
<published>2020-03-24T15:12:07+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=89ef050b8c049b9a6f0e2c70408fc93c826c55e0'/>
<id>89ef050b8c049b9a6f0e2c70408fc93c826c55e0</id>
<content type='text'>
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib. Most of this
is autogenerated, as described below, but there is one manual change
necessary:

nova/tests/functional/regressions/test_bug_1781286.py
  We need to avoid using 'fixtures.MockPatch' since fixtures is using
  'mock' (the library) under the hood and a call to 'mock.patch.stop'
  found in that test will now "stop" mocks from the wrong library. We
  have discussed making this configurable but the option proposed isn't
  that pretty [1] so this is better.

The remainder was auto-generated with the following (hacky) script, with
one or two manual tweaks after the fact:

  import glob

  for path in glob.glob('nova/tests/**/*.py', recursive=True):
      with open(path) as fh:
          lines = fh.readlines()
      if 'import mock\n' not in lines:
          continue
      import_group_found = False
      create_first_party_group = False
      for num, line in enumerate(lines):
          line = line.strip()
          if line.startswith('import ') or line.startswith('from '):
              tokens = line.split()
              for lib in (
                  'ddt', 'six', 'webob', 'fixtures', 'testtools'
                  'neutron', 'cinder', 'ironic', 'keystone', 'oslo',
              ):
                  if lib in tokens[1]:
                      create_first_party_group = True
                      break
              if create_first_party_group:
                  break
              import_group_found = True
          if not import_group_found:
              continue
          if line.startswith('import ') or line.startswith('from '):
              tokens = line.split()
              if tokens[1] &gt; 'unittest':
                  break
              elif tokens[1] == 'unittest' and (
                  len(tokens) == 2 or tokens[4] &gt; 'mock'
              ):
                  break
          elif not line:
              break
      if create_first_party_group:
          lines.insert(num, 'from unittest import mock\n\n')
      else:
          lines.insert(num, 'from unittest import mock\n')
      del lines[lines.index('import mock\n')]
      with open(path, 'w+') as fh:
          fh.writelines(lines)

Note that we cannot remove mock from our requirements files yet due to
importing pypowervm unit test code in nova unit tests. This library
still uses the mock lib, and since we are importing test code and that
lib (correctly) only declares mock in its test-requirements.txt, mock
would not otherwise be installed and would cause errors while loading
nova unit test code.

[1] https://github.com/testing-cabal/fixtures/pull/49

Change-Id: Id5b04cf2f6ca24af8e366d23f15cf0e5cac8e1cc
Signed-off-by: Stephen Finucane &lt;stephenfin@redhat.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib. Most of this
is autogenerated, as described below, but there is one manual change
necessary:

nova/tests/functional/regressions/test_bug_1781286.py
  We need to avoid using 'fixtures.MockPatch' since fixtures is using
  'mock' (the library) under the hood and a call to 'mock.patch.stop'
  found in that test will now "stop" mocks from the wrong library. We
  have discussed making this configurable but the option proposed isn't
  that pretty [1] so this is better.

The remainder was auto-generated with the following (hacky) script, with
one or two manual tweaks after the fact:

  import glob

  for path in glob.glob('nova/tests/**/*.py', recursive=True):
      with open(path) as fh:
          lines = fh.readlines()
      if 'import mock\n' not in lines:
          continue
      import_group_found = False
      create_first_party_group = False
      for num, line in enumerate(lines):
          line = line.strip()
          if line.startswith('import ') or line.startswith('from '):
              tokens = line.split()
              for lib in (
                  'ddt', 'six', 'webob', 'fixtures', 'testtools'
                  'neutron', 'cinder', 'ironic', 'keystone', 'oslo',
              ):
                  if lib in tokens[1]:
                      create_first_party_group = True
                      break
              if create_first_party_group:
                  break
              import_group_found = True
          if not import_group_found:
              continue
          if line.startswith('import ') or line.startswith('from '):
              tokens = line.split()
              if tokens[1] &gt; 'unittest':
                  break
              elif tokens[1] == 'unittest' and (
                  len(tokens) == 2 or tokens[4] &gt; 'mock'
              ):
                  break
          elif not line:
              break
      if create_first_party_group:
          lines.insert(num, 'from unittest import mock\n\n')
      else:
          lines.insert(num, 'from unittest import mock\n')
      del lines[lines.index('import mock\n')]
      with open(path, 'w+') as fh:
          fh.writelines(lines)

Note that we cannot remove mock from our requirements files yet due to
importing pypowervm unit test code in nova unit tests. This library
still uses the mock lib, and since we are importing test code and that
lib (correctly) only declares mock in its test-requirements.txt, mock
would not otherwise be installed and would cause errors while loading
nova unit test code.

[1] https://github.com/testing-cabal/fixtures/pull/49

Change-Id: Id5b04cf2f6ca24af8e366d23f15cf0e5cac8e1cc
Signed-off-by: Stephen Finucane &lt;stephenfin@redhat.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix typos</title>
<updated>2022-05-30T12:10:00+00:00</updated>
<author>
<name>Rajesh Tailor</name>
<email>ratailor@redhat.com</email>
</author>
<published>2022-05-23T11:26:20+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=2521810e553593f8d02adeef0f089b60bc7f71a6'/>
<id>2521810e553593f8d02adeef0f089b60bc7f71a6</id>
<content type='text'>
This change fixes some of the typos in unit tests as well
as in nova code-base.

Change-Id: I209bbb270baf889fcb2b9a4d1ce0ab4a962d0d0e
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This change fixes some of the typos in unit tests as well
as in nova code-base.

Change-Id: I209bbb270baf889fcb2b9a4d1ce0ab4a962d0d0e
</pre>
</div>
</content>
</entry>
<entry>
<title>guestfs: With libguestfs &gt;= v1.41.1 decode returned bytes to string</title>
<updated>2021-04-23T13:02:35+00:00</updated>
<author>
<name>Lee Yarwood</name>
<email>lyarwood@redhat.com</email>
</author>
<published>2021-04-23T11:14:42+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=606d588e3eca1d88ad26b4c2cfa3f2e1d5ed553e'/>
<id>606d588e3eca1d88ad26b4c2cfa3f2e1d5ed553e</id>
<content type='text'>
libguestfs &gt;= v1.41.1 and commit 0ee02e0117527 changed the return type
of read_file from string to bytes.

https://github.com/libguestfs/libguestfs/commit/0ee02e0117527b86a31b2a88a14994ce7f15571f

As we don't check the version of libguestfs installed this change
handles both the original behaviour where a string is returned and the
newer behaviour by decoding any returned bytes to a string.

Closes-Bug: #1882421
Change-Id: I1c12b2903c1e5bf3a88394493456ad33233f3cd8
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
libguestfs &gt;= v1.41.1 and commit 0ee02e0117527 changed the return type
of read_file from string to bytes.

https://github.com/libguestfs/libguestfs/commit/0ee02e0117527b86a31b2a88a14994ce7f15571f

As we don't check the version of libguestfs installed this change
handles both the original behaviour where a string is returned and the
newer behaviour by decoding any returned bytes to a string.

Closes-Bug: #1882421
Change-Id: I1c12b2903c1e5bf3a88394493456ad33233f3cd8
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge "Remove VFSLocalFS"</title>
<updated>2021-03-16T17:33:45+00:00</updated>
<author>
<name>Zuul</name>
<email>zuul@review.opendev.org</email>
</author>
<published>2021-03-16T17:33:45+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=f55f5daed88a9c3b11d29834481b6f7e4fef763c'/>
<id>f55f5daed88a9c3b11d29834481b6f7e4fef763c</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge "Remove non-libguestfs file injection for libvirt"</title>
<updated>2021-03-15T11:07:45+00:00</updated>
<author>
<name>Zuul</name>
<email>zuul@review.opendev.org</email>
</author>
<published>2021-03-15T11:07:45+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=bcb78e5a0294579a249c0b676620ffe6508ed999'/>
<id>bcb78e5a0294579a249c0b676620ffe6508ed999</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove VFSLocalFS</title>
<updated>2021-03-03T16:55:43+00:00</updated>
<author>
<name>Balazs Gibizer</name>
<email>balazs.gibizer@est.tech</email>
</author>
<published>2021-03-03T16:51:39+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=4b32f9c9e3016ab21c36f5ab480999b7b55a7b9a'/>
<id>4b32f9c9e3016ab21c36f5ab480999b7b55a7b9a</id>
<content type='text'>
The fix Iac8496065c8b6212d7edac320659444ab341b513 removed the last user
of VFSLocalFS so this patch remove the class, the related tests and all
the privsep functions that become dead code after this cleanup.

Change-Id: Ia1eb1d93d1f9699a4027b7a07107109ab9a3a29a
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The fix Iac8496065c8b6212d7edac320659444ab341b513 removed the last user
of VFSLocalFS so this patch remove the class, the related tests and all
the privsep functions that become dead code after this cleanup.

Change-Id: Ia1eb1d93d1f9699a4027b7a07107109ab9a3a29a
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove non-libguestfs file injection for libvirt</title>
<updated>2021-03-03T16:54:57+00:00</updated>
<author>
<name>Sean Dague</name>
<email>sean@dague.net</email>
</author>
<published>2016-06-02T17:14:11+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=d06a10f09699ef260002cc3474b33f08aca06583'/>
<id>d06a10f09699ef260002cc3474b33f08aca06583</id>
<content type='text'>
This is a security concern, as mounting filesystems on the host has
had previous CVEs around executing code on the host. libguestfs is
much safer, and is the only way we should allow this.

Some caveats came up during the discussion of the bug and this change
which are documented in the release note.

Co-Authored-By: Matt Riedemann &lt;mriedem.os@gmail.com&gt;

Closes-Bug: #1552042

Change-Id: Iac8496065c8b6212d7edac320659444ab341b513
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is a security concern, as mounting filesystems on the host has
had previous CVEs around executing code on the host. libguestfs is
much safer, and is the only way we should allow this.

Some caveats came up during the discussion of the bug and this change
which are documented in the release note.

Co-Authored-By: Matt Riedemann &lt;mriedem.os@gmail.com&gt;

Closes-Bug: #1552042

Change-Id: Iac8496065c8b6212d7edac320659444ab341b513
</pre>
</div>
</content>
</entry>
<entry>
<title>tests: Poison os.uname</title>
<updated>2021-02-20T15:32:15+00:00</updated>
<author>
<name>Stephen Finucane</name>
<email>stephenfin@redhat.com</email>
</author>
<published>2021-02-12T15:53:46+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=f7e3e179911e0a7fbad0d108c202c475560dbcea'/>
<id>f7e3e179911e0a7fbad0d108c202c475560dbcea</id>
<content type='text'>
We shouldn't be looking up the architecture of the test node during
tests to ensure tests work across nodes with varying architectures.

Change-Id: I458b1db091e33c0b835e44b5a86de6c0a08f99a3
Signed-off-by: Stephen Finucane &lt;stephenfin@redhat.com&gt;
Co-authored-by: Lee Yarwood &lt;lyarwood@redhat.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We shouldn't be looking up the architecture of the test node during
tests to ensure tests work across nodes with varying architectures.

Change-Id: I458b1db091e33c0b835e44b5a86de6c0a08f99a3
Signed-off-by: Stephen Finucane &lt;stephenfin@redhat.com&gt;
Co-authored-by: Lee Yarwood &lt;lyarwood@redhat.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge "Fix invalid argument formatting in exception messages"</title>
<updated>2021-02-04T19:14:46+00:00</updated>
<author>
<name>Zuul</name>
<email>zuul@review.opendev.org</email>
</author>
<published>2021-02-04T19:14:46+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/openstack/nova.git/commit/?id=7b5ac717bd338be32414ae25f60a4bfe4c94c0f4'/>
<id>7b5ac717bd338be32414ae25f60a4bfe4c94c0f4</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
