1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import logging
import os
import re
import subprocess
import sys
import yaml
# NOTE(SamYaple): Update the search path to prefer PROJECT_ROOT as the source
# of packages to import if we are using local tools instead of
# pip installed kolla tools
PROJECT_ROOT = os.path.abspath(os.path.join(
os.path.dirname(os.path.realpath(__file__)), '..'))
if PROJECT_ROOT not in sys.path:
sys.path.insert(0, PROJECT_ROOT)
from kolla.common import config
logging.basicConfig(level=logging.INFO)
LOG = logging.getLogger(__name__)
RELEASE_REPO = 'https://github.com/openstack/releases'
TARGET = '/tmp/releases'
SKIP_PROJECTS = {
'rally': 'Rally is not managed by openstack/releases project',
'nova-novncproxy': ('nova-novncproxy is not managed by'
' openstack/releases project'),
'nova-spicehtml5proxy': ('nova-spicehtml5proxy is not managed'
' by openstack/releases project'),
'openstack-base': 'There is no tag for requirements project',
'tempest': 'tempest is not managed by openstack/releases project'
}
RE_DEFAULT_BRANCH = re.compile('^defaultbranch=stable/(.*)')
RE_FILENAME = re.compile('(?P<project_name>.*)-(?P<tag>[^-]*).tar.gz')
def update_releases_repo():
if not os.path.exists(TARGET):
cmd = ['git', 'clone', RELEASE_REPO, TARGET]
else:
cmd = ['git', '--git-dir', os.path.join(TARGET, '.git'), '--work-tree',
TARGET, 'pull']
subprocess.call(cmd)
def get_default_branch():
gitreview_file = os.path.join(PROJECT_ROOT, '.gitreview')
if not os.path.exists(gitreview_file):
return
with open(gitreview_file, 'r') as gitreview:
for line in gitreview:
branches = RE_DEFAULT_BRANCH.findall(line)
if branches:
return branches[0]
def load_all_info(openstack_release):
projects = {}
release_path = os.path.join(TARGET, 'deliverables', openstack_release)
if not os.path.exists(release_path):
raise ValueError(
'Can not find openstack release: "%s"' % openstack_release)
for deliverable in os.listdir(release_path):
if not deliverable.endswith('.yaml'):
continue
with open(os.path.join(release_path, deliverable)) as f:
info = yaml.safe_load(f)
if 'releases' in info and len(info['releases']) > 0:
latest_release = info['releases'][-1]
latest_version = latest_release['version']
for project in latest_release['projects']:
project_name = project['repo'].split('/')[-1]
projects[project_name] = latest_version
if 'tarball-base' in project:
projects[project['tarball-base']] = latest_version
return projects
def main():
parser = argparse.ArgumentParser(
description='Check and update OpenStack service version.')
parser.add_argument('--openstack-release', '-r',
default=get_default_branch(),
help='OpenStack release name')
parser.add_argument('--include-independent', '-i',
default=False, action='store_true',
help='Whether update independent projects')
parser.add_argument('--check', '-c',
default=False, action='store_true',
help='Run without update config.py file')
conf = parser.parse_args(sys.argv[1:])
if not conf.openstack_release:
raise ValueError('Can not detect openstack release. Please assign'
' it through "--openstack-release" parameter')
LOG.info('Update using openstack release: "%s"', conf.openstack_release)
if conf.check:
LOG.info('Run in check only mode')
update_releases_repo()
projects = load_all_info(openstack_release=conf.openstack_release)
independents_projects = load_all_info(openstack_release='_independent')
with open(os.path.join(PROJECT_ROOT, 'kolla/common/config.py')) as f:
config_py = f.read()
for key in sorted(config.SOURCES):
independent_project = False
value = config.SOURCES[key]
if key in SKIP_PROJECTS:
LOG.info('%s is skiped: %s', key, SKIP_PROJECTS[key])
continue
# get project name from location
location = value['location']
filename = os.path.basename(location)
match = RE_FILENAME.match(filename)
if match:
project_name, old_tag = match.groups()
else:
raise ValueError('Can not parse "%s"' % filename)
latest_tag = projects.get(project_name, None)
if not latest_tag:
latest_tag = independents_projects.get(project_name, None)
if latest_tag:
independent_project = True
else:
LOG.warning('Can not find %s project release', project_name)
continue
if latest_tag and old_tag != latest_tag:
if independent_project and not conf.include_independent:
LOG.warning('%s is an independent project, please update it'
' manually. Possible need upgrade from %s to %s',
project_name, old_tag, latest_tag)
continue
LOG.info('Update %s from %s to %s', project_name, old_tag,
latest_tag)
old_str = '{}-{}'.format(project_name, old_tag)
new_str = '{}-{}'.format(project_name, latest_tag)
config_py = config_py.replace(old_str, new_str)
if not conf.check:
with open(os.path.join(PROJECT_ROOT, 'kolla/common/config.py'),
'w') as f:
f.write(config_py)
if __name__ == '__main__':
main()
|