Beispiel #1
0
 def test_make_vlan_tag_excludes_None_by_default(self):
     # Artificially limit randint to a very narrow range, to guarantee
     # some repetition in its output, and virtually guarantee that we test
     # both outcomes of the flip-a-coin call in make_vlan_tag.
     random = self.patch(factory_module, "random")
     random.randint.side_effect = [1, 2]
     outcomes = {factory.make_vlan_tag(), factory.make_vlan_tag()}
     self.assertEqual({1, 2}, outcomes)
Beispiel #2
0
 def test_make_vlan_tag_includes_None_if_allow_none(self):
     random = self.patch(factory_module, "random")
     random.choice.side_effect = [True, False, False]
     random.randint.side_effect = [1, 2]
     self.assertEqual({None, 1, 2}, {
         factory.make_vlan_tag(allow_none=True),
         factory.make_vlan_tag(allow_none=True),
         factory.make_vlan_tag(allow_none=True),
     })
Beispiel #3
0
 def test_returns_with_vlan_tag(self):
     cluster = factory.make_name('cluster')
     base_interface = self.make_interface()
     vlan_tag = factory.make_vlan_tag()
     interface = '%s.%d' % (base_interface, vlan_tag)
     expected_name = '%s-%s-%d' % (cluster, base_interface, vlan_tag)
     self.assertEqual(
         (expected_name, '%d' % vlan_tag),
         get_name_and_vlan_from_cluster_interface(cluster, interface))
Beispiel #4
0
 def test_returns_name_with_vlan_tag_and_alias(self):
     cluster = factory.make_name('cluster')
     base_interface = self.make_interface()
     vlan_tag = factory.make_vlan_tag()
     alias = randint(0, 99)
     interface = '%s.%d:%d' % (base_interface, vlan_tag, alias)
     expected_name = '%s-%s-%d-%d' % (
         cluster,
         base_interface,
         vlan_tag,
         alias,
     )
     self.assertEqual(
         (expected_name, '%d' % vlan_tag),
         get_name_and_vlan_from_cluster_interface(cluster, interface))
Beispiel #5
0
 def test_returns_name_with_alias_and_vlan_tag(self):
     cluster = factory.make_name("cluster")
     base_interface = self.make_interface()
     vlan_tag = factory.make_vlan_tag()
     alias = randint(0, 99)
     interface = "%s:%d.%d" % (base_interface, alias, vlan_tag)
     expected_name = "%s-%s-%d-%d" % (
         cluster,
         base_interface,
         alias,
         vlan_tag,
     )
     self.assertEqual(
         (expected_name, "%d" % vlan_tag),
         get_name_and_vlan_from_cluster_interface(cluster, interface),
     )