def test_constructor(self):
     """ Basic test that constructor is working"""
     config = GlanceSyncConfig(stream=self.stream)
     forcesyncs = set(['d93462dc-e7c7-4716-ab64-3cbc109b201f',
                       '3471db65-a449-41d5-9090-b8889ee404cb'])
     self.assertEquals(config.targets['master']['forcesyncs'], forcesyncs)
     self.assertIn('master', config.targets)
     self.assertIn('experimental', config.targets)
    def test_fields(self):
        """check all the other fields"""
        condition = "image.is_public and ('nid' in "\
            " image.user_properties or 'type' in image.user_properties)"

        config = GlanceSyncConfig(stream=self.stream)

        self.assertIn('master', config.targets)
        self.assertIn('experimental', config.targets)
        master = config.targets['master']
        experimental = config.targets['experimental']
        self.assertEquals(config.master_region, 'Spain')
        self.assertEquals(config.max_children, 1)
        self.assertEquals(config.preferable_order, [
            'Trento', 'Lannion', 'Waterford', 'Berlin', 'Prague'])
        self.assertEquals(master['replace'], set())
        self.assertEquals(master['rename'], set())
        self.assertEquals(master['dontupdate'], set())
        self.assertEquals(master['metadata_set'],
                          set(['nid', 'type', 'sdc_aware', 'nid_version']))
        self.assertEquals(master['metadata_condition'],
                          compile(condition, 'metadata_condition', 'eval'))
        self.assertEquals(master['user'], 'user1')
        self.assertEquals(master['password'], 'fakepassword,ofcourse')
        self.assertEquals(master['keystone_url'], 'http://server:4730/v2.0')
        self.assertEquals(master['tenant'], 'tenant1')
        self.assertFalse(master['only_tenant_images'])
        self.assertEquals(master['ignore_regions'], set())
        self.assertEquals(experimental['replace'], set())
        self.assertEquals(experimental['rename'], set())
        self.assertEquals(experimental['dontupdate'], set())
        self.assertEquals(experimental['metadata_set'],
                          set(['nid', 'type', 'sdc_aware', 'nid_version']))
        self.assertNotIn('metadata_condition', experimental)
        self.assertEquals(experimental['user'], 'user2')
        self.assertEquals(experimental['password'], 'fakepassword,ofcourse')
        self.assertEquals(experimental['keystone_url'],
                          'http://server2:4730/v2.0')
        self.assertEquals(experimental['tenant'], 'tenant2')
        self.assertTrue(experimental['only_tenant_images'])
        self.assertTrue(master['support_obsolete_images'])
        self.assertFalse(experimental['support_obsolete_images'])
        self.assertEquals(experimental['ignore_regions'], set(['Spain']))
        self.assertEquals(experimental['tenant_id'], 'tenant2_id')
        self.assertEquals(master['list_images_timeout'], 20)
        self.assertTrue(master['use_keystone_v3'])
        self.assertFalse(experimental['use_keystone_v3'])
 def test_content_empty(self):
     config = GlanceSyncConfig()
     self.assertEquals(config.master_region, 'Valladolid')
     self.assertEquals(config.max_children, 1)
     self.assertEquals(config.preferable_order, list())
     self.assertIn('master', config.targets.keys())
     self.assertEquals(config.targets['master']['user'], 'user')
     self.assertEquals(config.targets['master']['password'], 'password')
     self.assertEquals(config.targets['master']['keystone_url'], 'url')
     self.assertEquals(config.targets['master']['tenant'], 'tenant')
     self.assertEquals(config.targets['master']['replace'], set())
     self.assertEquals(config.targets['master']['rename'], set())
     self.assertEquals(config.targets['master']['dontupdate'], set())
     self.assertEquals(config.targets['master']['forcesyncs'], set())
     self.assertEquals(config.targets['master']['ignore_regions'], set())
     self.assertEquals(config.targets['master']['metadata_set'], set())
     self.assertTrue(config.targets['master']['only_tenant_images'])
 def test_content_empty(self):
     config = GlanceSyncConfig(stream=StringIO.StringIO(
         configuration_incomplete))
     self.assertEquals(config.images_dir, '/var/lib/glance/images')
     self.assertEquals(config.master_region, 'Spain2')
     self.assertEquals(config.max_children, 1)
     self.assertEquals(config.preferable_order, list())
     self.assertIn('master', config.targets.keys())
     self.assertEquals(config.targets['master']['user'], 'user')
     self.assertEquals(config.targets['master']['password'], 'password')
     self.assertEquals(config.targets['master']['keystone_url'], 'url')
     self.assertEquals(config.targets['master']['tenant'], 'tenant')
     self.assertEquals(config.targets['master']['replace'], set())
     self.assertEquals(config.targets['master']['rename'], set())
     self.assertEquals(config.targets['master']['dontupdate'], set())
     self.assertEquals(config.targets['master']['forcesyncs'], set())
     self.assertEquals(config.targets['master']['ignore_regions'], set())
     self.assertEquals(config.targets['master']['metadata_set'], set())
     self.assertFalse(config.targets['master']['only_tenant_images'])
 def test_constructor(self):
     config = GlanceSyncConfig()
     self.assertTrue(config)
 def test_order4(self):
     """Test without parameters and without environemnt. The default file
     must be readed"""
     del os.environ['GLANCESYNC_CONFIG']
     config = GlanceSyncConfig()
     self.assertEquals(config.master_region, 'region_etcfile')
 def test_order3(self):
     """Test passing the file parameter, without environment. The specified
     path must have more priority than the default path"""
     del os.environ['GLANCESYNC_CONFIG']
     config = GlanceSyncConfig(self.tempfile2.name)
     self.assertEquals(config.master_region, 'region_file')
 def test_order2b(self):
     """Test without passing nothing. The environment must have more
     priority than the default file"""
     config = GlanceSyncConfig()
     self.assertEquals(config.master_region, 'region_environment')
 def test_order2(self):
     """Test to pass the configuration passing only a file. Also the
     environment is set and exists the default configuration file.
     The environment must have more priority than the file"""
     config = GlanceSyncConfig(self.tempfile2.name)
     self.assertEquals(config.master_region, 'region_environment')
 def test_order1b(self):
     """Test to pass the configuration passing only a stream. The
     environment is set and the default file exists. The stream
     must have the top priority"""
     config = GlanceSyncConfig(stream=self.stream)
     self.assertEquals(config.master_region, 'region_stream')
 def test_order1(self):
     """Test to pass the configuration using a stream and a file. Also
     the environment is set and exists the default configuration file
     The stream must have the top priority"""
     config = GlanceSyncConfig(self.tempfile.name, self.stream)
     self.assertEquals(config.master_region, 'region_stream')
 def test_constructor(self):
     config = GlanceSyncConfig(self.tempfile.name)
     forcesyncs = set(['d93462dc-e7c7-4716-ab64-3cbc109b201f',
                       '3471db65-a449-41d5-9090-b8889ee404cb'])
     self.assertEquals(config.targets['master']['forcesyncs'], forcesyncs)
 def test_override(self):
     """check overriding options passing a dictionary to constructor"""
     override = {'master.user': '******', 'only_tenant_images': 'False'}
     config = GlanceSyncConfig(stream=self.stream, override_d=override)
     self.assertEquals(config.targets['master']['user'], 'otheruser')
     self.assertFalse(config.targets['experimental']['only_tenant_images'])