Пример #1
0
    def _from_csv(cls,system,data,csv_type,log):
        """
        Import data from CSV file into System Objects
        """
        if 'key' in data and data['key']:
            try:
                key = Key.by_name(data['key'])
            except InvalidRequestError:
                log.append('%s: Invalid Key %s ' % (system.fqdn, data['key']))
                return False
        else:
            log.append('%s: Key must not be blank!' % system.fqdn)
            return False
        if 'key_value' in data and data['key_value']:
            if key.numeric:
                system_key_values = system.key_values_int
                try:
                    key_value = Key_Value_Int.by_key_value(system,
                                                           key,
                                                           data['key_value'])
                except InvalidRequestError:
                    key_value = Key_Value_Int(key=key,
                                              key_value=data['key_value'])
            else:
                system_key_values = system.key_values_string
                try:
                    key_value = Key_Value_String.by_key_value(system,
                                                           key,
                                                           data['key_value'])
                except InvalidRequestError:
                    key_value = Key_Value_String(key=key,
                                                 key_value=data['key_value'])
        else:
            log.append('%s: Key Value must not be blank!' % system.fqdn)
            return False
        deleted = False
        if 'deleted' in data:
            deleted = smart_bool(data['deleted'])
        if deleted:
            if key_value in system_key_values:
                system.record_activity(user=identity.current.user, service=u'CSV',
                        action=u'Removed', field=u'Key/Value',
                        old=u'%s/%s' % (data['key'],data['key_value']), new=u'')
                system_key_values.remove(key_value)
                if not key_value.id:
                    session.expunge(key_value)
        else:
            if key_value not in system_key_values:
                system.record_activity(user=identity.current.user, service=u'CSV',
                        action=u'Added', field=u'Key/Value', old=u'',
                        new=u'%s/%s' % (data['key'],data['key_value']))
                system_key_values.append(key_value)

        session.add(key_value)
        return True
Пример #2
0
 def test_keyvalue_does_not_cause_duplicate_rows(self):
     system = data_setup.create_system()
     disk_key = Key.by_name(u'DISK')
     system.key_values_int.extend([
             Key_Value_Int(disk_key, 30718),
             Key_Value_Int(disk_key, 140011),
             Key_Value_Int(disk_key, 1048570)])
     session.flush()
     filter = """
         <hostRequires>
             <and>
                 <system><name op="=" value="%s" /></system>
                 <key_value key="DISK" op="&gt;" value="9000" />
             </and>
         </hostRequires>
         """ % system.fqdn
     query = XmlHost.from_string(filter).apply_filter(System.query)
     self.assertEquals(len(query.all()), 1)
     # with the bug this count comes out as 3 instead of 1,
     # which doesn't sound so bad...
     # but when it's 926127 instead of 278, that's bad
     self.assertEquals(query.count(), 1)
Пример #3
0
 def test_by_multiple_key_values(self):
     with session.begin():
         self.system = data_setup.create_system()
         self.system.key_values_string.append(Key_Value_String(
             Key.by_name(u'CPUMODEL'), 'foocodename'))
         self.system.key_values_string.append(Key_Value_String(
             Key.by_name(u'HVM'), '1'))
         self.system.key_values_int.append(Key_Value_Int(
             Key.by_name(u'DISKSPACE'), '1024'))
     b = self.browser
     perform_search(b, [('Key/Value', 'HVM', 'is', '1'),
         ('Key/Value', 'CPUMODEL', 'is', 'foocodename'),
         ('Key/Value', 'DISKSPACE', 'greater than', '1000')])
     check_system_search_results(b, present=[self.system],
             absent=[self.another_system])
Пример #4
0
 def test_remove_key_value(self):
     with session.begin():
         self.system.key_values_int.append(
             Key_Value_Int(Key.by_name(u'NR_DISKS'), 100))
     orig_date_modified = self.system.date_modified
     b = self.browser
     login(b)
     self.go_to_system_view(tab='Key/Values')
     b.find_element_by_xpath(
         '//td[normalize-space(preceding-sibling::td[1]/text())'
         '="NR_DISKS" and '
         'normalize-space(text())="100"]')
     delete_and_confirm(
         b, '//tr[normalize-space(td[1]/text())="NR_DISKS" and '
         'normalize-space(td[2]/text())="100"]')
     self.assertEquals(
         b.find_element_by_class_name('flash').text, 'removed NR_DISKS/100')
     b.find_element_by_xpath('//div[@id="keys" and not(.//tr['
                             'normalize-space(td[1]/text())="NR_DISKS" and '
                             'normalize-space(td[2]/text())="100"])]')
     with session.begin():
         session.refresh(self.system)
         self.assert_(self.system.date_modified > orig_date_modified)
Пример #5
0
    def setUpClass(cls):
        cls.system_one_details = {
            'fqdn': u'a1',
            'type': u'Machine',
            'arch': u'i386',
            'status': u'Automated',
            'owner': data_setup.create_user(),
        }
        cls.system_one = data_setup.create_system(**cls.system_one_details)
        cls.system_one.loaned = data_setup.create_user()
        cls.system_one.numa = Numa(nodes=2)
        cls.system_one.key_values_string.append(
            Key_Value_String(Key.by_name(u'CPUMODEL'), 'foocodename'))
        cls.system_one.key_values_string.append(
            Key_Value_String(Key.by_name(u'HVM'), '1'))
        cls.system_one.cpu = Cpu(flags=['flag1', 'flag2'])

        cls.system_one.key_values_int.append(
            Key_Value_Int(Key.by_name(u'DISKSPACE'), '1024'))
        cls.system_one.key_values_int.append(
            Key_Value_Int(Key.by_name(u'MEMORY'), '4096'))

        cls.system_two_details = {
            'fqdn': u'a2',
            'type': u'Prototype',
            'arch': u'x86_64',
            'status': u'Manual',
            'owner': data_setup.create_user(),
        }
        cls.system_two = data_setup.create_system(**cls.system_two_details)
        cls.system_two.key_values_int.append(
            Key_Value_Int(Key.by_name(u'DISKSPACE'), '900'))
        cls.system_two.key_values_string.append(
            Key_Value_String(Key.by_name(u'HVM'), '1'))

        device_class = DeviceClass.lazy_create(device_class='class_type')
        device1 = Device.lazy_create(vendor_id='0000',
                                     device_id='0000',
                                     subsys_vendor_id='2223',
                                     subsys_device_id='2224',
                                     bus='0000',
                                     driver='0000',
                                     device_class_id=device_class.id,
                                     description='blah')
        cls.system_two.devices.append(device1)
        cls.system_three_details = {
            'fqdn': u'a3',
            'type': u'Laptop',
            'arch': u'ia64',
            'status': u'Automated',
            'owner': data_setup.create_user(),
        }
        cls.system_three = data_setup.create_system(**cls.system_three_details)
        cls.system_three.numa = Numa(nodes=1)
        device2 = Device.lazy_create(vendor_id='0000',
                                     device_id='0000',
                                     subsys_vendor_id='1111',
                                     subsys_device_id='1112',
                                     bus='0000',
                                     driver='0000',
                                     device_class_id=device_class.id,
                                     description='blah')
        cls.system_three.devices.append(device2)

        cls.system_four_details = {
            'status': u'Removed',
        }
        cls.system_four = data_setup.create_system(**cls.system_four_details)
        cls.system_four.key_values_string.append(
            Key_Value_String(Key.by_name(u'CPUMODEL'), 'foocodename'))