Commit Graph

1183 Commits

Author SHA1 Message Date
Cole Robinson
e47b34c05a Fix initrdinject and urltests with py3
A few random issues scattered about
2018-02-06 18:56:15 -05:00
Cole Robinson
3086c7fda9 Drop python3 compat imports
We are going completely python3
2018-02-06 18:56:15 -05:00
Cole Robinson
e90d728380 urlfetcher: Open local files as binary
Needed for proper functioning on python3
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
15bd408570 Replace raw_input() with input()
raw_input() was renamed to input() in Python 3

See https://www.python.org/dev/peps/pep-3111/
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
e3d35b2fb9 tests: cli: Handle UnicodeError when logging 2018-02-06 18:49:17 -05:00
Radostin Stoyanov
5146d66126 python3 compat: python3 strings have no decode() 2018-02-06 18:49:17 -05:00
Radostin Stoyanov
4d9c6141dd Convert the output of range() to list
In Python 2 the range() function returns a list [1].
In Python 3 the range function returns a range type [2] which
represents an immutable sequence of numbers [3].

[1] https://docs.python.org/2.7/library/functions.html#range
[2] https://docs.python.org/3/library/functions.html#func-range
[3] https://docs.python.org/3/library/stdtypes.html#typesseq-range
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
08c23477fd Fix re-raising exception
In Python 2 the raise command can take 3 objects as arguments which
are used to specify the exception to be raise as well as detailed
information and traceback [1].

In Python 3 the sintax is changed and now the keyword "from" and
"with_traceback" keyworkds are used to specify this information. [2]

Example which has the same behaviour for both Python 2 and 3:

    try:
        a = 1/0
    except Exception:
        import sys
        err = sys.exc_info()

        try:
                raise Exception("Test")
        except:
                pass

        if sys.version_info[0] == 2:
            exec("raise err[0], err[1], err[2]")
        else:
            raise
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
95c695d774 Convert long to int
- Python 2 only
k = 9223372036854775808L

- Python 2 and 3:
k = 9223372036854775808

See http://python-future.org/compatible_idioms.html#long-integers
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
6de65ab328 urlfetcher: Python 2/3 compatability for 'urllib'
The `urllib2` module has been split across several modules in Python 3
named `urllib.request` and `urllib.error`. [1]

[1] https://docs.python.org/2.7/library/urllib2.html
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
5553cbeb38 Replace ipaddr module with ipaddress
The `ipaddress` is available in Python 3.3+ [1] and backport for
Python 2 is available on PyPI [2].

The main differences between ipaddr and ipaddress are:

- ipaddress *Network classes are equivalent to the ipaddr *Network
  class counterparts with the strict flag set to True.
- ipaddress *Interface classes are equivalent to the ipaddr *Network
  class counterparts with the strict flag set to False.
- The factory functions in ipaddress were renamed to disambiguate them
  from classes.
- A few attributes were renamed to disambiguate their purpose as well.
  (eg. network -> network_address, numhosts -> num_addresses)
- A number of methods and functions which returned containers in ipaddr
  now return iterators. This includes subnets, address_exclude,
  summarize_address_range and collapse_address_list.

Another major difference is that in Python 2 the `ipaddress` module
must use unicode. [3]

[1] https://www.python.org/dev/peps/pep-3144/
[2] https://pypi.python.org/pypi/ipaddress
[3] https://github.com/phihag/ipaddress
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
978fb25ac7 Wrap keys(), values() in a list
In Python 3 dict.values() [1] , dict.keys() [2] and dict.items() [3]
return a view [4] of the dictionary’s values, keys and items.

In Python 2 these functions return a list. [5] [6] [7]

To resolve this we can convert the result of these function to a list.

[1] https://docs.python.org/3/library/stdtypes.html#dict.values
[2] https://docs.python.org/3/library/stdtypes.html#dict.keys
[3] https://docs.python.org/3/library/stdtypes.html#dict.items
[4] https://docs.python.org/3/library/stdtypes.html#dict-views
[5] https://docs.python.org/2/library/stdtypes.html#dict.items
[6] https://docs.python.org/2/library/stdtypes.html#dict.keys
[7] https://docs.python.org/2/library/stdtypes.html#dict.values
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
810ee09292 Replace ConfigParser with configparser
The ConfigParser module has been renamed to configparser in
Python 3. [1] Backport of this changes is also available for
Python 2. [2]

[1] https://docs.python.org/2/library/configparser.html
[2] https://pypi.python.org/pypi/configparser/3.2.0r3
2018-02-06 18:49:17 -05:00
Wim ten Have
708516c39e virtinst: add vcpupin support
Add vcpupin support to virt-install so that it can create guest
domains with statically allocated vcpu pinning towards a given cpuset.

Syntax: to pin vcpu=0 to cpuset="1,3" and vcpu=1 to cpuset=2

  --cputune vcpupin0.vcpu=0,vcpupin0.cpuset=1,3,vcpupin1.vcpu=1,vcpupin1.cpuset=2

generates below XML description for the guest domain.

  <cputune>
    <vcpupin vcpu="0" cpuset="1,3"/>
    <vcpupin vcpu="1" cpuset="2"/>
  </cputune>

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Signed-off-by: Menno Lageman <menno.lageman@oracle.com>
2018-02-06 10:21:56 -05:00
Rauno Väli
582c1d3ded devicedisk: copy all rbd pool host and auth for volume
(crobinso: add test suite coverage, fix some pylint)
2018-01-30 11:30:22 -05:00
Menno Lageman
ae5239358a virtinst: Add NUMA distance support
Now that libvirt has support for administration of distances between NUMA cells
it would be nice to be able to set those with virt-install directly instead of
having to 'virsh edit' the domain XML manually after installation.

For example

--cpu cell0.memory=1234,cell0.cpus=0-3,cell1.memory=5678,cell1.cpus=4-7,\
      cell0.distances.sibling0.id=0,cell0.distances.sibling0.value=10,\
      cell0.distances.sibling1.id=1,cell0.distances.sibling1.value=21,\
      cell1.distances.sibling0.id=0,cell1.distances.sibling0.value=21,\
      cell1.distances.sibling1.id=1,cell1.distances.sibling1.value=10

would generate the following XML:

     <cpu>
       <numa>
         <cell cpus="0-3" memory="1234">
           <distances>
             <sibling id="0" value="10"/>
             <sibling id="1" value="21"/>
           </distances>
         </cell>
         <cell cpus="4-7" memory="5678">
           <distances>
             <sibling id="0" value="21"/>
             <sibling id="1" value="10"/>
           </distances>
         </cell>
       </numa>
     </cpu>

Signed-off-by: Menno Lageman <menno.lageman@oracle.com>

(crobinso: rework cli format, drop some validation, drop man changes)
2018-01-30 11:19:54 -05:00
Cole Robinson
cb6fc20210 cli: Drop python2ism with OSError 2018-01-27 16:27:41 -05:00
Radostin Stoyanov
6712261510 Python 2/3 division compatability
In Python 2 the classic devision of integers returns an integer
but in Python 3 it might return float.

Example:
- Python 2:          - Python 3:
    >>> 9 / 4            >>> 9 / 4
    2                    2.25
    >>> 9 // 4           >>> 9 // 4
    2                    2
    >>> 9 / 4.0          >>> 9 / 4.0
    2.25                 2.25
    >>> 9 // 4.0         >>> 9 // 4.0
    2.0                  2.0

For more info see: https://www.python.org/dev/peps/pep-0238/
2018-01-27 15:30:17 -05:00
Cole Robinson
d66a438ae3 cli: Share find_inst_cb logic
All users follow a similar pattern, so generalize it
2018-01-26 14:09:06 -05:00
Cole Robinson
402b42b14a watchdog: Add proper label for 'dump' action 2018-01-19 10:28:29 -05:00
Pavel Hrdina
0e812e3c42 vnc: don't skip authentication for listen type none with fixed QEMU
This was fixed by commit <fa03cb7fd21> in QEMU.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1445239

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-16 09:42:11 +01:00
Pavel Hrdina
bc8c5b0778 cli: append "--attach" to virt-viewer if graphics has listen type none
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1527834

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-07 08:59:43 +01:00
Lin Ma
75eb62fdb1 virtinst: Add pretty_desc function for device address printing
Signed-off-by: Lin Ma <lma@suse.com>
2018-01-06 16:01:49 -05:00
Lin Ma
65db33fec0 virtinst: Add a compare_controller function for future use
Signed-off-by: Lin Ma <lma@suse.com>
2018-01-06 16:01:45 -05:00
Cole Robinson
26046c5948 urlfetcher: Fix detection with latest ALT media 2018-01-06 14:04:34 -05:00
Cole Robinson
a183031793 urlfetcher: More debian CD arch handling 2018-01-06 14:04:34 -05:00
Andrew Wong
a7aa02ffa9 virtinst: Use isoinfo to extract files from ISOs and block devices 2018-01-06 14:02:11 -05:00
Scott Garfinkle
249ff1ed36 virtio-scsi by default on power
Power architecture guests should default to virtio-scsi rather than spapr-scsi

Signed-off-by: Scott Garfinkle <scottgar@linux.vnet.ibm.com>
2017-12-20 13:30:45 -05:00
Pavel Hrdina
f3f9dd6b73 virtinst.support: fix copy&paste error
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-12-18 19:18:31 +01:00
Cole Robinson
fe59c33772 virtinst: storage: Don't generate UUID by default
Just let libvirt do it for us, it doesn't really add anything
2017-12-14 12:45:01 -05:00
Cole Robinson
c286593b56 virtinst: network: Don't generate UUID by default
Just let libvirt do it for us, it doesn't really add anything
2017-12-14 12:45:01 -05:00
Cole Robinson
8b4befae60 virtinst: Drop UUID validation
It's redundant as libvirt will give us these checks already, and we
aren't even testing it
2017-12-14 12:45:01 -05:00
Cole Robinson
5ac933e98a guest: Set default rendernode= if spice gl requested
Since this is required to work out of the box with qemu:///system
2017-11-25 17:29:02 -05:00
Andrew Wong
f836e47b70 virtinst: Fix _URLFetcher for reading files
_grabber() is used for both binary and text files.
2017-11-22 17:26:31 -05:00
Cole Robinson
f7c8cf9f66 devicepanic: Don't return empty model list (bz #1505532)
Callers don't expect it, and it breaks opening the addhardware dialog
for aarch64 VMs

https://bugzilla.redhat.com/show_bug.cgi?id=1505532
2017-10-27 09:42:54 +02:00
Cole Robinson
374a3779c4 urlfetcher: Write test file as binary content
Triggers an test_ui error otherwise:

TypeError: write() argument must be str, not bytes
2017-10-21 19:41:33 -04:00
Chen Hanxiao
7f1b4cee82 pycodestyle: fix all E125 warnings
Fix all E125:
     Continuation line with same indent as next logical line

   Also remove ignore options of E125

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2017-10-21 23:26:16 +08:00
Cole Robinson
999dbb3665 cli: Make _VirtCLIArgument instantiation less crazy
Motivation is that the other way had changed behavior with python3
which breaks things
2017-10-20 17:07:19 -04:00
Cole Robinson
b8fa0c6b67 xmlnsqemu: Order XML output like libvirt does
args before env
2017-10-20 16:13:04 -04:00
Cole Robinson
91c0669cf6 cli: Fix OrderedDict mutated during iteration on python3 2017-10-20 16:13:04 -04:00
Radostin Stoyanov
f41aafc721 Use enumerate instead of range and len 2017-10-20 13:18:31 -04:00
Radostin Stoyanov
a2bcd6c43a Do not compare between None and int
In Python 2 comparison between int and None is allowed but in
Pyhton 3 it is not.

Example:

Pyhton 2

    >>> None > 0
    False

Python 3

    >>> None > 0
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: '>' not supported between instances of 'NoneType' and 'int'
2017-10-20 13:18:31 -04:00
Radostin Stoyanov
75210ed37c Replace StringIO with io.(StringIO or BytesIO)
StringIO and cStringIO modules no longer exists in Python 3. [1]
Use either io.StringIO [2] for text or io.BytesIO [3] for bytes.

[1] http://docs.python.org/3.0/whatsnew/3.0.html
[2] https://docs.python.org/3/library/io.html#text-i-o
[3] https://docs.python.org/3/library/io.html#binary-i-o
2017-10-20 13:18:31 -04:00
Radostin Stoyanov
dff00d4fc0 Remove deprecated statvfs module
The statvfs module has been removed in Python 3. [1]
It is replaced by os.statvfs which is also available in Pyhton 2.

[1] https://docs.python.org/2/library/statvfs.html#module-statvfs
[2] https://docs.python.org/3/library/os.html#os.statvfs
2017-10-20 11:49:14 -04:00
Radostin Stoyanov
2d276ebed8 progress: Don't overwrite "format"
Do not overwrite built-in format. [1]

https://docs.python.org/2/library/functions.html#format
2017-10-20 11:49:14 -04:00
Radostin Stoyanov
bc3c9a9d7b progress: Remove unused import 2017-10-20 11:49:14 -04:00
Radostin Stoyanov
63fce081ed pycodestyle: Use isinstance() for type checking
This is E721 in pycodestyle [1]:
   "do not compare types, use ‘isinstance()’"

The main differece between "type() is" and "isinstance()" is that
isinstance() supports inheritance. [1]

This can be seen in the example below:
    >>> type(True) is int
    False
    >>> isinstance(True, int)
    True

As we can see in python 'bool' a subclass of 'int'.

[1] https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
[2] https://docs.python.org/2/library/functions.html#isinstance
2017-10-20 11:49:13 -04:00
Radostin Stoyanov
d1e1cf64a7 progress: Remove trailing white space 2017-10-20 11:49:12 -04:00
Pavel Hrdina
6e6f59e7ab diskbackend: get a proper size of existing block device while cloning
We cannot use os.statvfs() if the clone disk is a block device because
it gets stats about filesystem which in this case is "devtmpfs" mounted
as "/dev".

As a workaround we can seek to the end of the block device to get
the actual size.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1450908

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 09:12:05 +02:00
Pavel Hrdina
e73abe5a3a diskbackend: convert to long the calculated size
If we convert to long the disk size, it may end up "0".  The size is
in GiB so it can be "0.1".

Introduced by commit <fab55c128ff3f092039bb950ecfd337568d2a9a8>.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 09:06:44 +02:00