Ejemplo n.º 1
0
    def get_network_roles(
            cls, instance, merge_policy=NetworkRoleMergePolicy()):
        """Method for receiving network roles for particular cluster

        :param instance: nailgun.db.sqlalchemy.models.Cluster instance
        :param merge_policy: the policy to merge same roles
        :returns: List of network roles' descriptions
        """
        return PluginManager.get_network_roles(instance, merge_policy)
Ejemplo n.º 2
0
 def setUp(self):
     super(TestNetworkRoleMergePolicy, self).setUp()
     self.policy = NetworkRoleMergePolicy()
Ejemplo n.º 3
0
 def setUp(self):
     super(TestNetworkRoleMergePolicy, self).setUp()
     self.policy = NetworkRoleMergePolicy()
Ejemplo n.º 4
0
class TestNetworkRoleMergePolicy(BaseTestCase):
    def setUp(self):
        super(TestNetworkRoleMergePolicy, self).setUp()
        self.policy = NetworkRoleMergePolicy()

    @staticmethod
    def _make_plugin_network_role(**kwargs):
        properties = {
            'subnet': True,
            'gateway': False,
            'vip': []
        }

        properties.update(kwargs)

        return {
            'id': 'test_network_role',
            'default_mapping': consts.NETWORKS.public,
            'properties': properties
        }

    def test_apply_path(self):
        target = self._make_plugin_network_role(vip=[{'name': 'test_vip_a'}])
        patch = self._make_plugin_network_role(vip=[{'name': 'test_vip_b'}])
        self.policy.apply_patch(target, patch)
        expected = self._make_plugin_network_role(
            vip=[{'name': 'test_vip_a'}, {'name': 'test_vip_b'}]
        )

        self.assertDictEqual(expected, target)

    def test_apply_patch_vips_without_duplicates(self):
        target = self._make_plugin_network_role(
            vip=[{'name': 'test_vip_a'}, {'name': 'test_vip_b'}]
        )
        patch = self._make_plugin_network_role(vip=[{'name': 'test_vip_a'}])
        self.policy.apply_patch(target, patch)
        self.assertItemsEqual(
            [{'name': 'test_vip_a'}, {'name': 'test_vip_b'}],
            target['properties']['vip']
        )

    def test_apply_patch_fail_if_conflict(self):
        with self.assertRaisesRegexp(errors.UnresolvableConflict, 'subnet'):
            self.policy.apply_patch(
                self._make_plugin_network_role(subnet=True),
                self._make_plugin_network_role(subnet=False)
            )

        with self.assertRaisesRegexp(errors.UnresolvableConflict, 'prop1'):
            self.policy.apply_patch(
                self._make_plugin_network_role(prop1=0.1),
                self._make_plugin_network_role(prop1=1)
            )

    def test_apply_path_fail_if_vip_conflict(self):
        with self.assertRaisesRegexp(
                errors.UnresolvableConflict,
                "VIP 'test' conflicts with existing one"):
            self.policy.apply_patch(
                self._make_plugin_network_role(
                    vip=[{"name": "test", "value": 1}]
                ),
                self._make_plugin_network_role(
                    vip=[{"name": "test", "value": 2}]
                )
            )
Ejemplo n.º 5
0
class TestNetworkRoleMergePolicy(BaseTestCase):
    def setUp(self):
        super(TestNetworkRoleMergePolicy, self).setUp()
        self.policy = NetworkRoleMergePolicy()

    @staticmethod
    def _make_plugin_network_role(**kwargs):
        properties = {'subnet': True, 'gateway': False, 'vip': []}

        properties.update(kwargs)

        return {
            'id': 'test_network_role',
            'default_mapping': consts.NETWORKS.public,
            'properties': properties
        }

    def test_apply_path(self):
        target = self._make_plugin_network_role(vip=[{'name': 'test_vip_a'}])
        patch = self._make_plugin_network_role(vip=[{'name': 'test_vip_b'}])
        self.policy.apply_patch(target, patch)
        expected = self._make_plugin_network_role(vip=[{
            'name': 'test_vip_a'
        }, {
            'name': 'test_vip_b'
        }])

        self.assertDictEqual(expected, target)

    def test_apply_patch_vips_without_duplicates(self):
        target = self._make_plugin_network_role(vip=[{
            'name': 'test_vip_a'
        }, {
            'name': 'test_vip_b'
        }])
        patch = self._make_plugin_network_role(vip=[{'name': 'test_vip_a'}])
        self.policy.apply_patch(target, patch)
        self.assertItemsEqual([{
            'name': 'test_vip_a'
        }, {
            'name': 'test_vip_b'
        }], target['properties']['vip'])

    def test_apply_patch_fail_if_conflict(self):
        with self.assertRaisesRegexp(errors.UnresolvableConflict, 'subnet'):
            self.policy.apply_patch(
                self._make_plugin_network_role(subnet=True),
                self._make_plugin_network_role(subnet=False))

        with self.assertRaisesRegexp(errors.UnresolvableConflict, 'prop1'):
            self.policy.apply_patch(self._make_plugin_network_role(prop1=0.1),
                                    self._make_plugin_network_role(prop1=1))

    def test_apply_path_fail_if_vip_conflict(self):
        with self.assertRaisesRegexp(errors.UnresolvableConflict,
                                     "VIP 'test' conflicts with existing one"):
            self.policy.apply_patch(
                self._make_plugin_network_role(vip=[{
                    "name": "test",
                    "value": 1
                }]),
                self._make_plugin_network_role(vip=[{
                    "name": "test",
                    "value": 2
                }]))