topology plugin doesn't properly handle:
- creation of segment with direction 'none' and then upgrade to other
  direction
- downgrade of direction

These situations are now forbidden in API.

part of: https://fedorahosted.org/freeipa/ticket/4302
--
Petr Vobornik
From 89703bf789885ef4919e5ca4d647537752f3f5c3 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Wed, 10 Jun 2015 14:44:09 +0200
Subject: [PATCH] topology: restrict direction changes

topology plugin doesn't properly handle:
- creation of segment with direction 'none' and then upgrade to other
  direction
- downgrade of direction

These situations are now forbidden in API.

part of: https://fedorahosted.org/freeipa/ticket/4302
---
 API.txt                            |  6 +++---
 VERSION                            |  5 ++---
 install/ui/src/freeipa/topology.js |  4 ++--
 ipalib/plugins/topology.py         | 10 +++++++++-
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/API.txt b/API.txt
index beb3891eff5de0eab72878a87435a02187ee36af..08abdc3494c5b4c037a168cf4fe952fb374862ff 100644
--- a/API.txt
+++ b/API.txt
@@ -4567,7 +4567,7 @@ arg: Str('topologysuffixcn', cli_name='topologysuffix', multivalue=False, primar
 arg: Str('cn', attribute=True, cli_name='name', maxlength=255, multivalue=False, primary_key=True, required=True)
 option: Str('addattr*', cli_name='addattr', exclude='webui')
 option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
-option: StrEnum('iparepltoposegmentdirection', attribute=True, cli_name='direction', default=u'both', multivalue=False, required=True, values=(u'both', u'left-right', u'right-left', u'none'))
+option: StrEnum('iparepltoposegmentdirection', attribute=True, cli_name='direction', default=u'both', multivalue=False, required=True, values=(u'both', u'left-right', u'right-left'))
 option: Str('iparepltoposegmentleftnode', attribute=True, cli_name='leftnode', maxlength=255, multivalue=False, pattern='^[a-zA-Z0-9.][a-zA-Z0-9.-]{0,252}[a-zA-Z0-9.$-]?$', required=True)
 option: Str('iparepltoposegmentrightnode', attribute=True, cli_name='rightnode', maxlength=255, multivalue=False, pattern='^[a-zA-Z0-9.][a-zA-Z0-9.-]{0,252}[a-zA-Z0-9.$-]?$', required=True)
 option: StrEnum('nsds5replicaenabled', attribute=True, cli_name='enabled', multivalue=False, required=False, values=(u'on', u'off'))
@@ -4596,7 +4596,7 @@ arg: Str('topologysuffixcn', cli_name='topologysuffix', multivalue=False, primar
 arg: Str('criteria?', noextrawhitespace=False)
 option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
 option: Str('cn', attribute=True, autofill=False, cli_name='name', maxlength=255, multivalue=False, primary_key=True, query=True, required=False)
-option: StrEnum('iparepltoposegmentdirection', attribute=True, autofill=False, cli_name='direction', default=u'both', multivalue=False, query=True, required=False, values=(u'both', u'left-right', u'right-left', u'none'))
+option: StrEnum('iparepltoposegmentdirection', attribute=True, autofill=False, cli_name='direction', default=u'both', multivalue=False, query=True, required=False, values=(u'both', u'left-right', u'right-left'))
 option: Str('iparepltoposegmentleftnode', attribute=True, autofill=False, cli_name='leftnode', maxlength=255, multivalue=False, pattern='^[a-zA-Z0-9.][a-zA-Z0-9.-]{0,252}[a-zA-Z0-9.$-]?$', query=True, required=False)
 option: Str('iparepltoposegmentrightnode', attribute=True, autofill=False, cli_name='rightnode', maxlength=255, multivalue=False, pattern='^[a-zA-Z0-9.][a-zA-Z0-9.-]{0,252}[a-zA-Z0-9.$-]?$', query=True, required=False)
 option: StrEnum('nsds5replicaenabled', attribute=True, autofill=False, cli_name='enabled', multivalue=False, query=True, required=False, values=(u'on', u'off'))
@@ -4620,7 +4620,7 @@ arg: Str('cn', attribute=True, cli_name='name', maxlength=255, multivalue=False,
 option: Str('addattr*', cli_name='addattr', exclude='webui')
 option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
 option: Str('delattr*', cli_name='delattr', exclude='webui')
-option: StrEnum('iparepltoposegmentdirection', attribute=True, autofill=False, cli_name='direction', default=u'both', multivalue=False, required=False, values=(u'both', u'left-right', u'right-left', u'none'))
+option: StrEnum('iparepltoposegmentdirection', attribute=True, autofill=False, cli_name='direction', default=u'both', multivalue=False, required=False, values=(u'both', u'left-right', u'right-left'))
 option: Str('iparepltoposegmentleftnode', attribute=True, autofill=False, cli_name='leftnode', maxlength=255, multivalue=False, pattern='^[a-zA-Z0-9.][a-zA-Z0-9.-]{0,252}[a-zA-Z0-9.$-]?$', required=False)
 option: Str('iparepltoposegmentrightnode', attribute=True, autofill=False, cli_name='rightnode', maxlength=255, multivalue=False, pattern='^[a-zA-Z0-9.][a-zA-Z0-9.-]{0,252}[a-zA-Z0-9.$-]?$', required=False)
 option: StrEnum('nsds5replicaenabled', attribute=True, autofill=False, cli_name='enabled', multivalue=False, required=False, values=(u'on', u'off'))
diff --git a/VERSION b/VERSION
index d0ce89e2231e1d8eb6d4282ebf8c8ffdf8781e7a..346af80582b78904a6f274a40897db65f170531d 100644
--- a/VERSION
+++ b/VERSION
@@ -90,6 +90,5 @@ IPA_DATA_VERSION=20100614120000
 #                                                      #
 ########################################################
 IPA_API_VERSION_MAJOR=2
-IPA_API_VERSION_MINOR=127
-# Last change: pvoborni - rename topologysegment_refresh to
-# topologysegment_reinitialize
+IPA_API_VERSION_MINOR=128
+# Last change: pvoborni - toposegment direction restrictions
diff --git a/install/ui/src/freeipa/topology.js b/install/ui/src/freeipa/topology.js
index 51714d99f9e1b3f6a8099f64333eb74f48016a95..f0d44f66d12a350828d653809ac9dee5ad078cb9 100644
--- a/install/ui/src/freeipa/topology.js
+++ b/install/ui/src/freeipa/topology.js
@@ -132,7 +132,7 @@ return {
                             $type: 'radio',
                             name: 'iparepltoposegmentdirection',
                             options: IPA.create_options([
-                                'both', 'left-right', 'right-left', 'none'
+                                'both', 'left-right', 'right-left'
                             ]),
                             default_value: 'both'
                         }
@@ -181,7 +181,7 @@ return {
                 $type: 'radio',
                 name: 'iparepltoposegmentdirection',
                 options: IPA.create_options([
-                    'both', 'left-right', 'right-left', 'none'
+                    'both', 'left-right', 'right-left'
                 ]),
                 default_value: 'both'
             }
diff --git a/ipalib/plugins/topology.py b/ipalib/plugins/topology.py
index d055602a863a589ab35758b1e1b51a0e0934dfab..ab8c9869f2a73471661a0d73416ecec12d84bcc7 100644
--- a/ipalib/plugins/topology.py
+++ b/ipalib/plugins/topology.py
@@ -96,7 +96,7 @@ class topologysegment(LDAPObject):
             'iparepltoposegmentdirection',
             cli_name='direction',
             label=_('Connectivity'),
-            values=(u'both', u'left-right', u'right-left', u'none'),
+            values=(u'both', u'left-right', u'right-left'),
             default=u'both',
             doc=_('Direction of replication between left and right replication '
                   'node'),
@@ -231,6 +231,14 @@ class topologysegment_mod(LDAPUpdate):
         assert isinstance(dn, DN)
         validate_domain_level(self.api)
         self.obj.validate_nodes(ldap, dn, entry_attrs)
+
+        direction = entry_attrs.get('iparepltoposegmentdirection')
+        if direction and direction != u'both':
+            raise errors.ValidationError(
+                name='direction',
+                error=_('downgrade of connectivity is not supported')
+            )
+
         return dn
 
 
-- 
2.1.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to