1 # Copyright 2019 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 import n2vc
.k8s_juju_conn
19 from base
import get_juju_public_key
21 from osm_common
.fslocal
import FsLocal
27 parser
= argparse
.ArgumentParser()
28 parser
.add_argument("--cluster_uuid", help='The UUID of an existing cluster to use', default
=None)
29 parser
.add_argument("--reset", action
="store_true")
30 return parser
.parse_args()
36 reuse_cluster_uuid
= args
.cluster_uuid
38 log
= logging
.getLogger()
39 log
.level
= logging
.DEBUG
41 # Extract parameters from the environment in order to run our tests
42 vca_host
= os
.getenv('VCA_HOST', '127.0.0.1')
43 vca_port
= os
.getenv('VCA_PORT', 17070)
44 vca_user
= os
.getenv('VCA_USER', 'admin')
45 vca_charms
= os
.getenv('VCA_CHARMS', None)
46 vca_secret
= os
.getenv('VCA_SECRET', None)
47 vca_ca_cert
= os
.getenv('VCA_CACERT', None)
49 # Get the Juju Public key
50 juju_public_key
= get_juju_public_key()
52 with
open(juju_public_key
, 'r') as f
:
53 juju_public_key
= f
.read()
55 raise Exception("No Juju Public Key found")
59 'path': '/srv/app/storage'
62 fs
.fs_connect(storage
)
64 client
= n2vc
.k8s_juju_conn
.K8sJujuConnector(
65 kubectl_command
='/snap/bin/kubectl',
66 juju_command
='/snap/bin/juju',
71 # kubectl config view --raw
75 # kubecfg = subprocess.getoutput('microk8s.config')
77 kubecfg
= subprocess
.getoutput('kubectl config view --raw')
80 # k8screds = yaml.load(kubecfg, Loader=yaml.FullLoader)
82 kdu_model
= "./tests/bundles/k8s-zookeeper.yaml"
85 cluster_uuid
, _
= await client
.init_env(kubecfg
, namespace
, reuse_cluster_uuid
=reuse_cluster_uuid
)
88 if not reuse_cluster_uuid
:
89 # This is a new cluster, so install to it
92 # async def install(self, cluster_uuid, kdu_model, atomic=True, timeout=None, params=None):
93 # TODO: Re-add storage declaration to bundle. The API doesn't support the storage option yet. David is investigating.
96 kdu_instance
= await client
.install(cluster_uuid
, kdu_model
, atomic
=True, timeout
=600)
100 print("Getting status")
101 status
= await client
.status_kdu(cluster_uuid
, kdu_instance
)
105 config
= await client
.inspect_kdu(kdu_model
)
108 readme
= await client
.help_kdu(kdu_model
)
113 Upgrade to a newer version of the bundle
115 kdu_model_upgrade
= "./tests/bundles/k8s-zookeeper-upgrade.yaml"
116 upgraded
= await client
.upgrade(cluster_uuid
, namespace
, kdu_model
=kdu_model_upgrade
)
118 kdu_model_upgrade
= "./tests/bundles/k8s-zookeeper-downgrade.yaml"
119 upgraded
= await client
.upgrade(cluster_uuid
, namespace
, kdu_model
=kdu_model_upgrade
)
125 await client
.reset(cluster_uuid
)
127 await client
.logout()
131 if __name__
== "__main__":