| #!/usr/bin/python |
| # Copyright 2012 Google Inc. All Rights Reserved. |
| |
| """This File executes create/modify/delete operations on ACS datastore. |
| |
| This class is used to interact with scripts that directly modifies |
| ACS datastore configuration. These ACS related actions may require |
| google3 dependencies |
| """ |
| |
| __author__ = 'Lehan Meng (lmeng@google.com)' |
| |
| |
| import os |
| import re |
| |
| |
| class ACS(object): |
| """This class executes operations that change Device profiles on ACS.""" |
| |
| def __init__(self, expected_version=None, **kwargs): |
| """Constructor for this Class.""" |
| self.acs_info = { |
| 'url': None, |
| # expected image version ID on ACS |
| 'imageVersion': expected_version, |
| 'outfile': 'cmdOutput.txt'} |
| for s in kwargs: |
| self.acs_info[s] = kwargs[s] |
| |
| def SetLogging(self, log): |
| """Setup the logging file(s).""" |
| self.log = log |
| |
| def SetImageVersion(self, expected_version): |
| """Set the expected image version that needs to be configured at ACS. |
| |
| Args: |
| expected_version: the version string of the expected image. |
| """ |
| m = re.match('\d+', expected_version) |
| if m is None: |
| info = self.log.CreateErrorInfo( |
| 'critical', |
| 'Error! Please use software id as expected image version value') |
| self.log.SendLine(None, info) |
| else: |
| self.acs_info['imageVersion'] = expected_version |
| |
| def SaveConfiguration(self): |
| """Run the ACS configuration script from Google3 location.""" |
| cur_dir = os.getcwd() |
| print '============' + cur_dir |
| os.chdir('/home/lmeng/git_project/google3/isp/' |
| 'fiber/testing/automated_tests/bulkupgrade/') |
| print '============' + os.getcwd() |
| os.system( |
| 'blaze test --notest_loasd --test_arg=--imageVersion=' |
| + self.acs_info['imageVersion'] |
| + ' --test_strategy=local :bulkupgrade_test ') |
| os.chdir(cur_dir) |
| print '============' + os.getcwd() |
| |
| def StubbyClientCall(self, cmd=None): |
| """This is the nbi_client stubby call to get parameter names and values.""" |
| p = os.popen(cmd, 'r') |
| log_list = [] |
| while 1: |
| line = p.readline() |
| if not line: break |
| log_list.append(line.strip()) |
| return log_list |
| |
| def ParseParameterNames(self, cmd_list): |
| """Parse the command output from nbi_client, retrieve parameter names.""" |
| if ('FAILED' in cmd_list[0]) or (not 'SUCCESS' in cmd_list[0]): |
| info = self.log.CreateErrorInfo( |
| 'Critical', 'nbi_clienet call failed. Check log for details.') |
| self.log.SendLine(None, info) |
| return False |
| |
| chk_list = [] |
| for line in cmd_list: |
| if 'name:' in line: |
| output = re.sub('.*\"(.*)\".*', r'\1', line) |
| output = re.sub(r'(\.)[\d]+(\.)', r'\1{i}\2', output) |
| if chk_list.count(output) < 1: |
| chk_list.append(output) |
| return chk_list |
| |
| |
| if __name__ == '__main__': |
| pass |