~sseman/juju-ci-tools/assess-min-version

« back to all changes in this revision

Viewing changes to jujupy.py

  • Committer: Aaron Bentley
  • Date: 2016-03-18 14:47:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1324.
  • Revision ID: aaron.bentley@canonical.com-20160318144706-z7wy9c21m3psi6g5
Introduce set_model_name, update tests, check controller on bootstrap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
    return state
149
149
 
150
150
 
 
151
 
 
152
 
151
153
def make_client(juju_path, debug, env_name, temp_env_name):
152
154
    env = SimpleEnvironment.from_config(env_name)
153
155
    if temp_env_name is not None:
154
 
        env.environment = temp_env_name
155
 
        env.config['name'] = temp_env_name
 
156
        env.set_model_name(temp_env_name)
156
157
    return EnvJujuClient.by_version(env, juju_path, debug)
157
158
 
158
159
 
462
463
        with temp_yaml_file(config_dict) as config_filename:
463
464
            yield config_filename
464
465
 
 
466
    def _check_bootstrap(self):
 
467
        if self.env.environment != self.env.controller.name:
 
468
            raise AssertionError(
 
469
                'Controller and environment names should not vary (yet)')
 
470
 
465
471
    def bootstrap(self, upload_tools=False, bootstrap_series=None):
466
472
        """Bootstrap a controller."""
 
473
        self._check_bootstrap()
467
474
        with self._bootstrap_config() as config_filename:
468
475
            args = self.get_bootstrap_args(
469
476
                upload_tools, config_filename, bootstrap_series)
471
478
 
472
479
    @contextmanager
473
480
    def bootstrap_async(self, upload_tools=False, bootstrap_series=None):
 
481
        self._check_bootstrap()
474
482
        with self._bootstrap_config() as config_filename:
475
483
            args = self.get_bootstrap_args(
476
484
                upload_tools, config_filename, bootstrap_series)
1161
1169
 
1162
1170
    def bootstrap(self, upload_tools=False, bootstrap_series=None):
1163
1171
        """Bootstrap a controller."""
 
1172
        self._check_bootstrap()
1164
1173
        args = self.get_bootstrap_args(upload_tools, bootstrap_series)
1165
1174
        self.juju('bootstrap', args, self.env.needs_sudo())
1166
1175
 
1167
1176
    @contextmanager
1168
1177
    def bootstrap_async(self, upload_tools=False):
 
1178
        self._check_bootstrap()
1169
1179
        args = self.get_bootstrap_args(upload_tools)
1170
1180
        with self.juju_async('bootstrap', args):
1171
1181
            yield
1891
1901
    def __ne__(self, other):
1892
1902
        return not self == other
1893
1903
 
 
1904
    def set_model_name(self, model_name, set_controller=True):
 
1905
        if set_controller:
 
1906
            self.controller.name = model_name
 
1907
        self.environment = model_name
 
1908
        self.config['name'] = model_name
 
1909
 
1894
1910
    @classmethod
1895
1911
    def from_config(cls, name):
1896
1912
        return cls._from_config(name)