Browse Source

Implementation of preupgrade-compute as task graph

- Add repo list to cluster settings
- Add package list to cluster settings
- Override repo list on computes via Hiera
- Clear old apt configuration
- Rsync latest puppet modules
- Use setup_repositories task to set up new repos
- Upgrade packages
- Remove override
- Roll back repo configuration

Change-Id: I2d3dc57702084dfd5ac771a6f55e11968f86f9f3
Dmitry Nikishov 2 years ago
parent
commit
ae8326e7f7

+ 96
- 0
deployment/puppet/octane_tasks/graphs/orig/preupgrade-compute.yaml View File

@@ -0,0 +1,96 @@
1
+# GROUPS
2
+- id: compute
3
+  type: group
4
+  role: [compute]
5
+  fault_tolerance: 0
6
+
7
+# TASKS
8
+- id: rsync_octane
9
+  type: sync
10
+  version: 2.1.0
11
+  groups: [compute]
12
+  requires: []
13
+  required_for: []
14
+  parameters:
15
+    src: rsync://{MASTER_IP}:/octane_code/puppet
16
+    dst: /etc/fuel/octane/
17
+    timeout: 180
18
+
19
+- id: override_repos_in_hiera
20
+  type: upload_file
21
+  version: 2.1.0
22
+  groups: [compute]
23
+  requires: []
24
+  required_for: []
25
+  parameters:
26
+    path: /etc/hiera/override/common.yaml
27
+    data:
28
+      yaql_exp: >
29
+        ({"repo_setup" => {"repos" => $.repo_setup.preupgrade_compute},
30
+          "preupgrade_packages" => $.preupgrade_packages}.toYaml())
31
+
32
+- id: cleanup_existing_repos
33
+  type: shell
34
+  version: 2.1.0
35
+  groups: [compute]
36
+  requires: []
37
+  required_for: []
38
+  parameters:
39
+    cmd: >
40
+      tar zcf /root/sources.list.d-backup-$(date +%F-%H%M).tar.gz /etc/apt/sources.list.d;
41
+      rm /etc/apt/sources.list.d/*.list || true
42
+    timeout: 60
43
+
44
+- id: rsync_latest_puppet
45
+  type: sync
46
+  version: 2.1.0
47
+  groups: [compute]
48
+  requires: []
49
+  required_for: []
50
+  parameters:
51
+    src: rsync://{MASTER_IP}:/puppet/modules/
52
+    dst: /etc/fuel/octane/latest_modules
53
+    timeout: 180
54
+
55
+- id: setup_new_repositories
56
+  type: puppet
57
+  version: 2.1.0
58
+  groups: [compute]
59
+  requires: [cleanup_existing_repos, rsync_latest_puppet, override_repos_in_hiera]
60
+  required_for: []
61
+  parameters:
62
+    puppet_manifest: /etc/fuel/octane/latest_modules/osnailyfacter/modular/fuel_pkgs/setup_repositories.pp
63
+    puppet_modules: /etc/fuel/octane/latest_modules
64
+    timeout: 600
65
+
66
+- id: stop_compute_services
67
+  type: puppet
68
+  version: 2.1.0
69
+  groups: [compute]
70
+  requires: [setup_new_repositories, rsync_octane]
71
+  required_for: []
72
+  parameters:
73
+    puppet_manifest: /etc/fuel/octane/puppet/octane_tasks/modular/stop_compute_services.pp
74
+    puppet_modules:  /etc/fuel/octane/puppet:/etc/puppet/modules
75
+    timeout: 360
76
+
77
+- id: preupgrade_compute
78
+  type: puppet
79
+  version: 2.1.0
80
+  groups: [compute]
81
+  requires: [stop_compute_services, rsync_octane, setup_new_repositories]
82
+  required_for: []
83
+  parameters:
84
+    puppet_manifest: /etc/fuel/octane/puppet/octane_tasks/modular/preupgrade_compute.pp
85
+    puppet_modules:  /etc/fuel/octane/puppet:/etc/puppet/modules
86
+    timeout: 360
87
+
88
+- id: remove_hiera_override
89
+  type: shell
90
+  version: 2.1.0
91
+  groups: [compute]
92
+  requires: [preupgrade_compute]
93
+  required_for: []
94
+  parameters:
95
+    cmd: rm /etc/hiera/override/common.yaml || true
96
+    timeout: 60

+ 47
- 0
deployment/puppet/octane_tasks/manifests/preupgrade_compute.pp View File

@@ -0,0 +1,47 @@
1
+# == Class: octane_tasks::preupgrade_compute
2
+#
3
+# This class upgrades required packages on compute node
4
+# inplace. See magic_consts.COMPUTE_PREUPGRADE_PACKAGES
5
+# for the complete list.
6
+#
7
+class octane_tasks::preupgrade_compute {
8
+  $preupgrade_packages = hiera('preupgrade_packages')
9
+  $preupgrade_packages_str = join($preupgrade_packages, ' ')
10
+
11
+  # As much as I would love to use package type, it just won't
12
+  # cut it. The to-be-updated packages have dependencies between
13
+  # each other, so it would take a strict ordering of the package
14
+  # list to do so. Assuming that passing the list to the resource
15
+  # makes Puppet realize these resources in the same order, they
16
+  # are present in the list.
17
+  Exec {
18
+    path    => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
19
+  }
20
+
21
+  exec { 'pre-upgrade-apt-get-update':
22
+    command => 'apt-get update',
23
+    before  => Exec['upgrade-packages'],
24
+  }
25
+
26
+  exec { 'upgrade-packages':
27
+    path        => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
28
+    command     => "apt-get install --only-upgrade --yes --force-yes \
29
+                    -o Dpkg::Options::=\"--force-confdef\" \
30
+                    -o Dpkg::Options::=\"--force-confold\" \
31
+                    ${preupgrade_packages_str}",
32
+    environment => ['DEBIAN_FRONTEND=noninteractive'],
33
+    before      => Anchor['packages-are-updated'],
34
+  }
35
+
36
+  anchor { 'packages-are-updated': }
37
+
38
+  service { 'nova-compute':
39
+    ensure    => running,
40
+    subscribe => Anchor['packages-are-updated'],
41
+  }
42
+
43
+  service { 'neutron-plugin-openvswitch-agent':
44
+    ensure    => running,
45
+    subscribe => Anchor['packages-are-updated'],
46
+  }
47
+}

+ 14
- 0
deployment/puppet/octane_tasks/manifests/stop_compute_services.pp View File

@@ -0,0 +1,14 @@
1
+# == Class: octane_tasks::stop_compute_service
2
+#
3
+# This class stops compute services to prepare
4
+# for inplace package updates.
5
+#
6
+class octane_tasks::stop_compute_services {
7
+  service { 'nova-compute':
8
+    ensure    => stopped,
9
+  }
10
+
11
+  service { 'neutron-plugin-openvswitch-agent':
12
+    ensure    => stopped,
13
+  }
14
+}

+ 3
- 0
deployment/puppet/octane_tasks/modular/preupgrade_compute.pp View File

@@ -0,0 +1,3 @@
1
+notice('MODULAR: octane_tasks::preupgrade_compute')
2
+
3
+include ::octane_tasks::preupgrade_compute

+ 3
- 0
deployment/puppet/octane_tasks/modular/stop_compute_services.pp View File

@@ -0,0 +1,3 @@
1
+notice('MODULAR: octane_tasks::stop_compute_services')
2
+
3
+include ::octane_tasks::stop_compute_services

+ 51
- 8
octane/commands/preupgrade_compute.py View File

@@ -18,6 +18,7 @@ from fuelclient import objects
18 18
 
19 19
 from octane import magic_consts
20 20
 from octane.util import apt
21
+from octane.util import deployment as deploy
21 22
 from octane.util import helpers
22 23
 from octane.util import ssh
23 24
 
@@ -80,20 +81,34 @@ def get_repos(release, master_ip=''):
80 81
     return repos
81 82
 
82 83
 
84
+def get_package_list(release):
85
+    version = release.data['version']
86
+    try:
87
+        packages = magic_consts.COMPUTE_PREUPGRADE_PACKAGES[version]
88
+    except KeyError:
89
+        LOG.exception("Info about packages for a release with id {0} "
90
+                      "does not exist".format(release.id))
91
+        raise
92
+    return packages
93
+
94
+
95
+def add_upgrade_attrs_to_settings(env, repos, packages):
96
+    attrs = env.get_settings_data()
97
+    attrs['editable']['repo_setup']['preupgrade_compute'] = {'value': repos,
98
+                                                             'type': 'hidden'}
99
+    attrs['editable']['common']['preupgrade_packages'] = {'value': packages,
100
+                                                          'type': 'hidden'}
101
+    env.set_settings_data(attrs)
102
+
103
+
83 104
 def preupgrade_compute(release_id, node_ids):
84 105
     nodes = [objects.node.Node(node_id) for node_id in node_ids]
85 106
     release = objects.Release(release_id)
86 107
     check_sanity(nodes, release)
87 108
     master_ip = helpers.get_astute_dict()["ADMIN_NETWORK"]['ipaddress']
88 109
 
89
-    version = release.data['version']
90 110
     repos = get_repos(release, master_ip)
91
-    try:
92
-        packages = magic_consts.COMPUTE_PREUPGRADE_PACKAGES[version]
93
-    except KeyError:
94
-        LOG.exception("Info about packages for a release with id {0} "
95
-                      "is not exist".format(release_id))
96
-        raise
111
+    packages = get_package_list(release)
97 112
 
98 113
     for node in nodes:
99 114
         change_repositories(node, repos)
@@ -101,6 +116,26 @@ def preupgrade_compute(release_id, node_ids):
101 116
         apt.upgrade_packages(node, packages)
102 117
 
103 118
 
119
+def preupgrade_compute_with_graph(release_id, node_ids):
120
+    nodes = [objects.node.Node(node_id) for node_id in node_ids]
121
+    release = objects.Release(release_id)
122
+    check_sanity(nodes, release)
123
+    master_ip = helpers.get_astute_dict()["ADMIN_NETWORK"]['ipaddress']
124
+
125
+    repos = get_repos(release, master_ip)
126
+    packages = get_package_list(release)
127
+    env_id = nodes[0].env.id
128
+    env = objects.environment.Environment(env_id)
129
+
130
+    # Add following data to cluster attributes:
131
+    # - new repositories
132
+    # - list of packages to be updated
133
+    add_upgrade_attrs_to_settings(env, repos, packages)
134
+
135
+    deploy.upload_graph(env_id, "orig")
136
+    deploy.execute_graph_and_wait('preupgrade-compute', env_id, node_ids)
137
+
138
+
104 139
 class PreupgradeComputeCommand(cmd.Command):
105 140
     """Preupgrade compute"""
106 141
 
@@ -118,7 +153,15 @@ class PreupgradeComputeCommand(cmd.Command):
118 153
             metavar='NODE_ID',
119 154
             help="IDs of compute nodes to be preupgraded",
120 155
             nargs="+")
156
+        parser.add_argument(
157
+            '--with-graph', action='store_true',
158
+            help='EXPERIMENTAL: Use Fuel deployment graphs'
159
+                 ' instead of python-based commands.')
121 160
         return parser
122 161
 
123 162
     def take_action(self, parsed_args):
124
-        preupgrade_compute(parsed_args.release_id, parsed_args.node_ids)
163
+        if parsed_args.with_graph:
164
+            preupgrade_compute_with_graph(parsed_args.release_id,
165
+                                          parsed_args.node_ids)
166
+        else:
167
+            preupgrade_compute(parsed_args.release_id, parsed_args.node_ids)

Loading…
Cancel
Save