def test_get_attribute(self): class X: def __init__(self): self.name = 'value' instance = X() Defaults.get_attribute(instance, 'name') assert instance.name == 'value'
def update(self, image_name, update_record): try: os_image = self.service.get_os_image(image_name) except Exception as e: raise AzureOsImageUpdateError( '%s: %s' % (type(e).__name__, format(e)) ) self.__decorate_os_image_attributes_for_update( os_image, update_record ) try: self.service.update_os_image_from_image_reference( image_name, os_image ) os_image_updated = self.service.get_os_image( image_name ) except Exception as e: raise AzureOsImageUpdateError( '%s: %s' % (type(e).__name__, format(e)) ) elements_not_changed = [] for name in sorted(update_record.keys()): value_desired = Defaults.get_attribute(os_image, name) value_current = Defaults.get_attribute(os_image_updated, name) if '_uri' in name: # Use normalized paths to compare, avoids false positives value_desired = os.path.normpath(value_desired) value_current = os.path.normpath(value_current) if value_desired != value_current: elements_not_changed.append(name) if elements_not_changed: message = [ 'The element(s) "%s" could not be updated.' % ','.join(elements_not_changed), 'Please check if your account is registered as image publisher' ] raise AzureOsImageUpdateError( ' '.join(message) )