Example #1
0
 def attachDeviceFlags(dom, xml, flags=0):
     myxml = objectify.fromstring(xml)
     if myxml.tag == 'memory':
         unit = myxml.target.size.get('unit')
         myxml.target.size.set('unit', 'KiB')
         myxml.target.size._setText(
             str(int(convert_data_size(myxml.target.size.text, unit,
                                       'KiB'))))
         xml = ET.tostring(myxml).decode('utf-8')
         dom.setMaxMemory(int(dom.maxMemory() + myxml.target.size))
     MockModel._mock_vms[dom.name()].append(xml)
Example #2
0
 def attachDeviceFlags(dom, xml, flags=0):
     myxml = objectify.fromstring(xml)
     if myxml.tag == 'memory':
         unit = myxml.target.size.get('unit')
         myxml.target.size.set('unit', 'KiB')
         myxml.target.size._setText(
             str(int(convert_data_size(myxml.target.size.text, unit, 'KiB')))
         )
         xml = ET.tostring(myxml).decode('utf-8')
         dom.setMaxMemory(int(dom.maxMemory() + myxml.target.size))
     MockModel._mock_vms[dom.name()].append(xml)
Example #3
0
    def test_convert_data_size(self):
        failure_data = [
            {'val': None, 'from': 'MiB'},
            {'val': self, 'from': 'MiB'},
            {'val': 1, 'from': None},
            {'val': 1, 'from': ''},
            {'val': 1, 'from': 'foo'},
            {'val': 1, 'from': 'kib'},
            {'val': 1, 'from': 'MiB', 'to': None},
            {'val': 1, 'from': 'MiB', 'to': ''},
            {'val': 1, 'from': 'MiB', 'to': 'foo'},
            {'val': 1, 'from': 'MiB', 'to': 'kib'},
        ]

        for d in failure_data:
            if 'to' in d:
                self.assertRaises(
                    InvalidParameter,
                    convert_data_size, d['val'], d['from'], d['to']
                )
            else:
                self.assertRaises(
                    InvalidParameter, convert_data_size, d['val'], d['from']
                )

        success_data = [
            {'got': convert_data_size(5, 'MiB', 'MiB'), 'want': 5},
            {'got': convert_data_size(5, 'MiB', 'KiB'), 'want': 5120},
            {'got': convert_data_size(5, 'MiB', 'M'), 'want': 5.24288},
            {'got': convert_data_size(5, 'MiB', 'GiB'), 'want': 0.0048828125},
            {'got': convert_data_size(5, 'MiB', 'Tb'), 'want': 4.194304e-05},
            {'got': convert_data_size(5, 'KiB', 'MiB'), 'want': 0.0048828125},
            {'got': convert_data_size(5, 'M', 'MiB'),
             'want': 4.76837158203125},
            {'got': convert_data_size(5, 'GiB', 'MiB'), 'want': 5120},
            {'got': convert_data_size(5, 'Tb', 'MiB'),
             'want': 596046.4477539062},
            {
                'got': convert_data_size(5, 'MiB'),
                'want': convert_data_size(5, 'MiB', 'B'),
            },
        ]

        for d in success_data:
            self.assertEqual(d['got'], d['want'])
Example #4
0
    def test_convert_data_size(self):
        failure_data = [{'val': None, 'from': 'MiB'},
                        {'val': self, 'from': 'MiB'},
                        {'val': 1,    'from': None},
                        {'val': 1,    'from': ''},
                        {'val': 1,    'from': 'foo'},
                        {'val': 1,    'from': 'kib'},
                        {'val': 1,    'from': 'MiB', 'to': None},
                        {'val': 1,    'from': 'MiB', 'to': ''},
                        {'val': 1,    'from': 'MiB', 'to': 'foo'},
                        {'val': 1,    'from': 'MiB', 'to': 'kib'}]

        for d in failure_data:
            if 'to' in d:
                self.assertRaises(InvalidParameter, convert_data_size,
                                  d['val'], d['from'], d['to'])
            else:
                self.assertRaises(InvalidParameter, convert_data_size,
                                  d['val'], d['from'])

        success_data = [{'got': convert_data_size(5, 'MiB', 'MiB'),
                         'want': 5},
                        {'got': convert_data_size(5, 'MiB', 'KiB'),
                         'want': 5120},
                        {'got': convert_data_size(5, 'MiB', 'M'),
                         'want': 5.24288},
                        {'got': convert_data_size(5, 'MiB', 'GiB'),
                         'want': 0.0048828125},
                        {'got': convert_data_size(5, 'MiB', 'Tb'),
                         'want': 4.194304e-05},
                        {'got': convert_data_size(5, 'KiB', 'MiB'),
                         'want': 0.0048828125},
                        {'got': convert_data_size(5, 'M', 'MiB'),
                         'want': 4.76837158203125},
                        {'got': convert_data_size(5, 'GiB', 'MiB'),
                         'want': 5120},
                        {'got': convert_data_size(5, 'Tb', 'MiB'),
                         'want': 596046.4477539062},
                        {'got': convert_data_size(5, 'MiB'),
                         'want': convert_data_size(5, 'MiB', 'B')}]

        for d in success_data:
            self.assertEquals(d['got'], d['want'])