Skip to content

Commit 743df77

Browse files
committed
[FIX] Add global check for ops min version
1 parent 4072b43 commit 743df77

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/ops/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
#OF ANY KIND, either express or implied. See the License for the specific language
99
#governing permissions and limitations under the License.
1010

11+
import pkg_resources
1112
import re
13+
from distutils.version import StrictVersion
1214
from subprocess import call, Popen, PIPE
1315
from ops.cli import display
1416

1517

18+
def validate_ops_version(min_ops_version):
19+
current_ops_version = [x.version for x in pkg_resources.working_set if x.project_name == "ops"][0]
20+
if StrictVersion(current_ops_version) < StrictVersion(min_ops_version):
21+
raise Exception("The current ops version {0} is lower than the minimum required version {1}. "
22+
"Please upgrade by following the instructions seen here: "
23+
"https://github.com/adobe/ops-cli#installing".format(current_ops_version, min_ops_version))
24+
25+
1626
class Executor(object):
1727
""" All cli commands usually return a dict(command=...) that will be executed by this handler"""
1828

src/ops/cli/terraform.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ops.terraform.terraform_cmd_generator import TerraformCommandGenerator
1616
from ops.hierarchical.composition_config_generator import TerraformConfigGenerator
1717
from distutils.version import StrictVersion
18+
from ops import validate_ops_version
1819
import pkg_resources
1920

2021
logger = logging.getLogger(__name__)
@@ -144,10 +145,7 @@ def check_ops_version(self):
144145
if "terraform" in self.cluster_config.conf:
145146
if "ops_min_version" in self.cluster_config.conf["terraform"]:
146147
ops_min_version = str(self.cluster_config.conf["terraform"]["ops_min_version"])
147-
current_ops_version = [x.version for x in pkg_resources.working_set if x.project_name == "ops"][0]
148-
if StrictVersion(current_ops_version) < StrictVersion(ops_min_version):
149-
raise Exception("The current ops version {0} is lower than the minimum required version {1} for cluster {2}".format(
150-
current_ops_version, ops_min_version, self.cluster_config_path))
148+
validate_ops_version(ops_min_version)
151149

152150
def run(self, args):
153151
self.check_ops_version()

src/ops/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
PluginInventoryGenerator, InventoryGenerator, CachedInventoryGenerator
3131
from inventory.plugin import ec2, legacy_pcs, cns, azr, skms
3232
from inventory.sshconfig import SshConfigGenerator
33-
from ops import OpsException, Executor
33+
from ops import OpsException, Executor, validate_ops_version
3434
from ops.jinja import Template
3535
from opsconfig import OpsConfig
3636

@@ -72,6 +72,7 @@ def __init__(self, argv=None):
7272
self.execute = auto(Executor)
7373

7474
self.configure()
75+
self.validate_ops_version()
7576

7677
def configure_parsers(self):
7778
self.root_parser = auto(RootParser)
@@ -130,6 +131,10 @@ def configure(self):
130131

131132
return args
132133

134+
def validate_ops_version(self):
135+
if 'ops.min_version' in self.ops_config:
136+
validate_ops_version(self.ops_config['ops.min_version'])
137+
133138
def run(self):
134139
if 'refresh_cache' in vars(self.console_args):
135140
os.environ['REFRESH_CACHE'] = str(self.console_args.refresh_cache)

0 commit comments

Comments
 (0)