Exemple #1
0
    def test_convert_to_new_format_collision(self):
        """Test the conversion of old to new format with collisions
           That matches e.g. the MAAS case specifying old and new config"""
        cfg_1_and_3 = {
            'apt': {
                'proxy': 'http://192.168.122.1:8000/'
            },
            'apt_proxy': 'http://192.168.122.1:8000/'
        }
        cfg_3_only = {'apt': {'proxy': 'http://192.168.122.1:8000/'}}
        cfgconflict = {
            'apt': {
                'proxy': 'http://192.168.122.1:8000/'
            },
            'apt_proxy': 'ftp://192.168.122.1:8000/'
        }

        # collision (equal)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3)
        self.assertEqual(newcfg, cfg_3_only)
        # collision (equal, so ok to remove)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_3_only)
        self.assertEqual(newcfg, cfg_3_only)
        # collision (unequal)
        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format(cfgconflict)
Exemple #2
0
    def test_convert_to_new_format_collision(self):
        """Test the conversion of old to new format with collisions
        That matches e.g. the MAAS case specifying old and new config"""
        cfg_1_and_3 = {
            "apt": {
                "proxy": "http://192.168.122.1:8000/"
            },
            "apt_proxy": "http://192.168.122.1:8000/",
        }
        cfg_3_only = {"apt": {"proxy": "http://192.168.122.1:8000/"}}
        cfgconflict = {
            "apt": {
                "proxy": "http://192.168.122.1:8000/"
            },
            "apt_proxy": "ftp://192.168.122.1:8000/",
        }

        # collision (equal)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3)
        self.assertEqual(newcfg, cfg_3_only)
        # collision (equal, so ok to remove)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_3_only)
        self.assertEqual(newcfg, cfg_3_only)
        # collision (unequal)
        match = "Old and New.*unequal.*apt_proxy"
        with self.assertRaisesRegex(ValueError, match):
            cc_apt_configure.convert_to_v3_apt_format(cfgconflict)
Exemple #3
0
 def test_convert_with_apt_mirror_as_empty_string(self):
     # an empty apt_mirror is the same as no apt_mirror
     empty_m_found = cc_apt_configure.convert_to_v3_apt_format(
         {"apt_mirror": ""}
     )
     default_found = cc_apt_configure.convert_to_v3_apt_format({})
     self.assertEqual(default_found, empty_m_found)
Exemple #4
0
 def test_no_old_content(self):
     mirror = "http://my.mirror/ubuntu"
     mydata = {"apt": {"primary": {"arches": ["default"], "uri": mirror}}}
     expected = copy.deepcopy(mydata)
     self.assertEqual(
         expected, cc_apt_configure.convert_to_v3_apt_format(mydata)
     )
Exemple #5
0
    def test_convert_to_new_format_collision(self):
        """Test the conversion of old to new format with collisions
           That matches e.g. the MAAS case specifying old and new config"""
        cfg_1_and_3 = {'apt': {'proxy': 'http://192.168.122.1:8000/'},
                       'apt_proxy': 'http://192.168.122.1:8000/'}
        cfg_3_only = {'apt': {'proxy': 'http://192.168.122.1:8000/'}}
        cfgconflict = {'apt': {'proxy': 'http://192.168.122.1:8000/'},
                       'apt_proxy': 'ftp://192.168.122.1:8000/'}

        # collision (equal)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3)
        self.assertEqual(newcfg, cfg_3_only)
        # collision (equal, so ok to remove)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_3_only)
        self.assertEqual(newcfg, cfg_3_only)
        # collision (unequal)
        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format(cfgconflict)
Exemple #6
0
    def test_convert_to_new_format(self):
        """Test the conversion of old to new format"""
        cfg1 = {'source': 'deb $MIRROR $RELEASE multiverse',
                'filename': self.aptlistfile}
        cfg2 = {'source': 'deb $MIRROR $RELEASE main',
                'filename': self.aptlistfile2}
        cfg3 = {'source': 'deb $MIRROR $RELEASE universe',
                'filename': self.aptlistfile3}
        cfg = {'apt_sources': [cfg1, cfg2, cfg3]}
        checkcfg = {self.aptlistfile: {'filename': self.aptlistfile,
                                       'source': 'deb $MIRROR $RELEASE '
                                                 'multiverse'},
                    self.aptlistfile2: {'filename': self.aptlistfile2,
                                        'source': 'deb $MIRROR $RELEASE main'},
                    self.aptlistfile3: {'filename': self.aptlistfile3,
                                        'source': 'deb $MIRROR $RELEASE '
                                                  'universe'}}

        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg)
        self.assertEqual(newcfg['apt']['sources'], checkcfg)

        # convert again, should stay the same
        newcfg2 = cc_apt_configure.convert_to_v3_apt_format(newcfg)
        self.assertEqual(newcfg2['apt']['sources'], checkcfg)

        # should work without raising an exception
        cc_apt_configure.convert_to_v3_apt_format({})

        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format({'apt_sources': 5})
Exemple #7
0
    def test_convert_to_new_format_dict_collision(self):
        cfg1 = {'source': 'deb $MIRROR $RELEASE multiverse',
                'filename': self.aptlistfile}
        cfg2 = {'source': 'deb $MIRROR $RELEASE main',
                'filename': self.aptlistfile2}
        cfg3 = {'source': 'deb $MIRROR $RELEASE universe',
                'filename': self.aptlistfile3}
        fullv3 = {self.aptlistfile: {'filename': self.aptlistfile,
                                     'source': 'deb $MIRROR $RELEASE '
                                               'multiverse'},
                  self.aptlistfile2: {'filename': self.aptlistfile2,
                                      'source': 'deb $MIRROR $RELEASE main'},
                  self.aptlistfile3: {'filename': self.aptlistfile3,
                                      'source': 'deb $MIRROR $RELEASE '
                                                'universe'}}
        cfg_3_only = {'apt': {'sources': fullv3}}
        cfg_1_and_3 = {'apt_sources': [cfg1, cfg2, cfg3]}
        cfg_1_and_3.update(cfg_3_only)

        # collision (equal, so ok to remove)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3)
        self.assertEqual(newcfg, cfg_3_only)
        # no old spec (same result)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_3_only)
        self.assertEqual(newcfg, cfg_3_only)

        diff = {self.aptlistfile: {'filename': self.aptlistfile,
                                   'source': 'deb $MIRROR $RELEASE '
                                             'DIFFERENTVERSE'},
                self.aptlistfile2: {'filename': self.aptlistfile2,
                                    'source': 'deb $MIRROR $RELEASE main'},
                self.aptlistfile3: {'filename': self.aptlistfile3,
                                    'source': 'deb $MIRROR $RELEASE '
                                              'universe'}}
        cfg_3_only = {'apt': {'sources': diff}}
        cfg_1_and_3_different = {'apt_sources': [cfg1, cfg2, cfg3]}
        cfg_1_and_3_different.update(cfg_3_only)

        # collision (unequal by dict having a different entry)
        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3_different)

        missing = {self.aptlistfile: {'filename': self.aptlistfile,
                                      'source': 'deb $MIRROR $RELEASE '
                                                'multiverse'}}
        cfg_3_only = {'apt': {'sources': missing}}
        cfg_1_and_3_missing = {'apt_sources': [cfg1, cfg2, cfg3]}
        cfg_1_and_3_missing.update(cfg_3_only)
        # collision (unequal by dict missing an entry)
        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3_missing)
Exemple #8
0
    def test_convert_to_new_format(self):
        """Test the conversion of old to new format"""
        cfg1 = {
            'source': 'deb $MIRROR $RELEASE multiverse',
            'filename': self.aptlistfile
        }
        cfg2 = {
            'source': 'deb $MIRROR $RELEASE main',
            'filename': self.aptlistfile2
        }
        cfg3 = {
            'source': 'deb $MIRROR $RELEASE universe',
            'filename': self.aptlistfile3
        }
        cfg = {'apt_sources': [cfg1, cfg2, cfg3]}
        checkcfg = {
            self.aptlistfile: {
                'filename': self.aptlistfile,
                'source': 'deb $MIRROR $RELEASE '
                'multiverse'
            },
            self.aptlistfile2: {
                'filename': self.aptlistfile2,
                'source': 'deb $MIRROR $RELEASE main'
            },
            self.aptlistfile3: {
                'filename': self.aptlistfile3,
                'source': 'deb $MIRROR $RELEASE '
                'universe'
            }
        }

        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg)
        self.assertEqual(newcfg['apt']['sources'], checkcfg)

        # convert again, should stay the same
        newcfg2 = cc_apt_configure.convert_to_v3_apt_format(newcfg)
        self.assertEqual(newcfg2['apt']['sources'], checkcfg)

        # should work without raising an exception
        cc_apt_configure.convert_to_v3_apt_format({})

        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format({'apt_sources': 5})
Exemple #9
0
    def test_convert_to_new_format(self):
        """Test the conversion of old to new format"""
        cfg1 = {
            "source": "deb $MIRROR $RELEASE multiverse",
            "filename": self.aptlistfile,
        }
        cfg2 = {
            "source": "deb $MIRROR $RELEASE main",
            "filename": self.aptlistfile2,
        }
        cfg3 = {
            "source": "deb $MIRROR $RELEASE universe",
            "filename": self.aptlistfile3,
        }
        cfg = {"apt_sources": [cfg1, cfg2, cfg3]}
        checkcfg = {
            self.aptlistfile: {
                "filename": self.aptlistfile,
                "source": "deb $MIRROR $RELEASE multiverse",
            },
            self.aptlistfile2: {
                "filename": self.aptlistfile2,
                "source": "deb $MIRROR $RELEASE main",
            },
            self.aptlistfile3: {
                "filename": self.aptlistfile3,
                "source": "deb $MIRROR $RELEASE universe",
            },
        }

        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg)
        self.assertEqual(newcfg["apt"]["sources"], checkcfg)

        # convert again, should stay the same
        newcfg2 = cc_apt_configure.convert_to_v3_apt_format(newcfg)
        self.assertEqual(newcfg2["apt"]["sources"], checkcfg)

        # should work without raising an exception
        cc_apt_configure.convert_to_v3_apt_format({})

        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format({"apt_sources": 5})
Exemple #10
0
 def test_no_old_content(self):
     mirror = 'http://my.mirror/ubuntu'
     mydata = {'apt': {'primary': {'arches': ['default'], 'uri': mirror}}}
     expected = copy.deepcopy(mydata)
     self.assertEqual(expected,
                      cc_apt_configure.convert_to_v3_apt_format(mydata))
Exemple #11
0
 def test_convert_with_apt_mirror(self):
     mirror = 'http://my.mirror/ubuntu'
     f = cc_apt_configure.convert_to_v3_apt_format({'apt_mirror': mirror})
     self.assertIn(mirror, set(m['uri'] for m in f['apt']['primary']))
Exemple #12
0
    def test_convert_to_new_format_dict_collision(self):
        cfg1 = {
            "source": "deb $MIRROR $RELEASE multiverse",
            "filename": self.aptlistfile,
        }
        cfg2 = {
            "source": "deb $MIRROR $RELEASE main",
            "filename": self.aptlistfile2,
        }
        cfg3 = {
            "source": "deb $MIRROR $RELEASE universe",
            "filename": self.aptlistfile3,
        }
        fullv3 = {
            self.aptlistfile: {
                "filename": self.aptlistfile,
                "source": "deb $MIRROR $RELEASE multiverse",
            },
            self.aptlistfile2: {
                "filename": self.aptlistfile2,
                "source": "deb $MIRROR $RELEASE main",
            },
            self.aptlistfile3: {
                "filename": self.aptlistfile3,
                "source": "deb $MIRROR $RELEASE universe",
            },
        }
        cfg_3_only = {"apt": {"sources": fullv3}}
        cfg_1_and_3 = {"apt_sources": [cfg1, cfg2, cfg3]}
        cfg_1_and_3.update(cfg_3_only)

        # collision (equal, so ok to remove)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3)
        self.assertEqual(newcfg, cfg_3_only)
        # no old spec (same result)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_3_only)
        self.assertEqual(newcfg, cfg_3_only)

        diff = {
            self.aptlistfile: {
                "filename": self.aptlistfile,
                "source": "deb $MIRROR $RELEASE DIFFERENTVERSE",
            },
            self.aptlistfile2: {
                "filename": self.aptlistfile2,
                "source": "deb $MIRROR $RELEASE main",
            },
            self.aptlistfile3: {
                "filename": self.aptlistfile3,
                "source": "deb $MIRROR $RELEASE universe",
            },
        }
        cfg_3_only = {"apt": {"sources": diff}}
        cfg_1_and_3_different = {"apt_sources": [cfg1, cfg2, cfg3]}
        cfg_1_and_3_different.update(cfg_3_only)

        # collision (unequal by dict having a different entry)
        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3_different)

        missing = {
            self.aptlistfile: {
                "filename": self.aptlistfile,
                "source": "deb $MIRROR $RELEASE multiverse",
            }
        }
        cfg_3_only = {"apt": {"sources": missing}}
        cfg_1_and_3_missing = {"apt_sources": [cfg1, cfg2, cfg3]}
        cfg_1_and_3_missing.update(cfg_3_only)
        # collision (unequal by dict missing an entry)
        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3_missing)
Exemple #13
0
 def test_convert_with_apt_mirror(self):
     mirror = "http://my.mirror/ubuntu"
     f = cc_apt_configure.convert_to_v3_apt_format({"apt_mirror": mirror})
     self.assertIn(mirror, set(m["uri"] for m in f["apt"]["primary"]))
 def test_convert_with_apt_mirror(self):
     mirror = 'http://my.mirror/ubuntu'
     f = cc_apt_configure.convert_to_v3_apt_format({'apt_mirror': mirror})
     self.assertIn(mirror, set(m['uri'] for m in f['apt']['primary']))
 def test_convert_with_apt_mirror_as_empty_string(self):
     # an empty apt_mirror is the same as no apt_mirror
     empty_m_found = cc_apt_configure.convert_to_v3_apt_format(
         {'apt_mirror': ''})
     default_found = cc_apt_configure.convert_to_v3_apt_format({})
     self.assertEqual(default_found, empty_m_found)
Exemple #16
0
    def test_convert_to_new_format_dict_collision(self):
        cfg1 = {
            'source': 'deb $MIRROR $RELEASE multiverse',
            'filename': self.aptlistfile
        }
        cfg2 = {
            'source': 'deb $MIRROR $RELEASE main',
            'filename': self.aptlistfile2
        }
        cfg3 = {
            'source': 'deb $MIRROR $RELEASE universe',
            'filename': self.aptlistfile3
        }
        fullv3 = {
            self.aptlistfile: {
                'filename': self.aptlistfile,
                'source': 'deb $MIRROR $RELEASE '
                'multiverse'
            },
            self.aptlistfile2: {
                'filename': self.aptlistfile2,
                'source': 'deb $MIRROR $RELEASE main'
            },
            self.aptlistfile3: {
                'filename': self.aptlistfile3,
                'source': 'deb $MIRROR $RELEASE '
                'universe'
            }
        }
        cfg_3_only = {'apt': {'sources': fullv3}}
        cfg_1_and_3 = {'apt_sources': [cfg1, cfg2, cfg3]}
        cfg_1_and_3.update(cfg_3_only)

        # collision (equal, so ok to remove)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3)
        self.assertEqual(newcfg, cfg_3_only)
        # no old spec (same result)
        newcfg = cc_apt_configure.convert_to_v3_apt_format(cfg_3_only)
        self.assertEqual(newcfg, cfg_3_only)

        diff = {
            self.aptlistfile: {
                'filename': self.aptlistfile,
                'source': 'deb $MIRROR $RELEASE '
                'DIFFERENTVERSE'
            },
            self.aptlistfile2: {
                'filename': self.aptlistfile2,
                'source': 'deb $MIRROR $RELEASE main'
            },
            self.aptlistfile3: {
                'filename': self.aptlistfile3,
                'source': 'deb $MIRROR $RELEASE '
                'universe'
            }
        }
        cfg_3_only = {'apt': {'sources': diff}}
        cfg_1_and_3_different = {'apt_sources': [cfg1, cfg2, cfg3]}
        cfg_1_and_3_different.update(cfg_3_only)

        # collision (unequal by dict having a different entry)
        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3_different)

        missing = {
            self.aptlistfile: {
                'filename': self.aptlistfile,
                'source': 'deb $MIRROR $RELEASE '
                'multiverse'
            }
        }
        cfg_3_only = {'apt': {'sources': missing}}
        cfg_1_and_3_missing = {'apt_sources': [cfg1, cfg2, cfg3]}
        cfg_1_and_3_missing.update(cfg_3_only)
        # collision (unequal by dict missing an entry)
        with self.assertRaises(ValueError):
            cc_apt_configure.convert_to_v3_apt_format(cfg_1_and_3_missing)
 def test_no_old_content(self):
     mirror = 'http://my.mirror/ubuntu'
     mydata = {'apt': {'primary': {'arches': ['default'], 'uri': mirror}}}
     expected = copy.deepcopy(mydata)
     self.assertEqual(expected,
                      cc_apt_configure.convert_to_v3_apt_format(mydata))