summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam Young <liam.young@canonical.com>2018-01-11 17:27:20 +0000
committerLiam Young <liam.young@canonical.com>2018-01-12 14:11:16 +0000
commitedd9b1face6aac248d134d9261574e451a8121e7 (patch)
tree03bb063104ee33d44f0986df97aea56707813254
parent0f14eac67221721b2df05931a667692f88e84f05 (diff)
Add action for running archive-deleted-rows
Add an action for moving stale data to shadow tables using nova-manage *1. This will speed up other operations such as map_instances which no longer need to work against stale data. *1 https://docs.openstack.org/nova/pike/cli/nova-manage.html Change-Id: I03f3d641b50cfc6f02262edb0f714ba6e9566775 Partial-Bug: #1742115
Notes
Notes (review): Verified+1: Canonical CI <uosci-testing-bot@ubuntu.com> Code-Review+2: Chris MacNaughton <chris.macnaughton@canonical.com> Workflow+1: Chris MacNaughton <chris.macnaughton@canonical.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 16 Jan 2018 07:17:01 +0000 Reviewed-on: https://review.openstack.org/532918 Project: openstack/charm-nova-cloud-controller Branch: refs/heads/master
-rw-r--r--actions.yaml7
-rwxr-xr-xactions/actions.py20
l---------actions/archive-data1
-rw-r--r--hooks/nova_cc_utils.py18
-rw-r--r--unit_tests/test_nova_cc_utils.py31
5 files changed, 75 insertions, 2 deletions
diff --git a/actions.yaml b/actions.yaml
index 002aec3..6ba7753 100644
--- a/actions.yaml
+++ b/actions.yaml
@@ -4,3 +4,10 @@ pause:
4 description: Pause the nova-cloud-controller unit. This action will stop related services. 4 description: Pause the nova-cloud-controller unit. This action will stop related services.
5resume: 5resume:
6 descrpition: Resume the nova-cloud-controller unit. This action will start related services. 6 descrpition: Resume the nova-cloud-controller unit. This action will start related services.
7archive-data:
8 descrpition: Run job to archive deleted rows in database
9 params:
10 batch-size:
11 type: integer
12 default: 10000
13 description: Archive old data to shadow tables
diff --git a/actions/actions.py b/actions/actions.py
index e59d45c..c6e43c8 100755
--- a/actions/actions.py
+++ b/actions/actions.py
@@ -19,11 +19,16 @@ import sys
19 19
20sys.path.append('hooks/') 20sys.path.append('hooks/')
21 21
22from charmhelpers.core.hookenv import action_fail 22from charmhelpers.core.hookenv import (
23 action_fail,
24 action_get,
25 action_set,
26)
23from nova_cc_utils import ( 27from nova_cc_utils import (
24 pause_unit_helper, 28 pause_unit_helper,
25 resume_unit_helper, 29 resume_unit_helper,
26 register_configs, 30 register_configs,
31 archive_deleted_rows,
27) 32)
28 33
29 34
@@ -40,9 +45,20 @@ def resume(args):
40 resume_unit_helper(register_configs()) 45 resume_unit_helper(register_configs())
41 46
42 47
48def archive_data(args):
49 """Run data archival process
50 @raises Exception should the archival fail"""
51 action_set({
52 'archive-deleted-rows': archive_deleted_rows(
53 max_rows=action_get('batch-size'))})
54
55
43# A dictionary of all the defined actions to callables (which take 56# A dictionary of all the defined actions to callables (which take
44# parsed arguments). 57# parsed arguments).
45ACTIONS = {"pause": pause, "resume": resume} 58ACTIONS = {
59 "pause": pause,
60 "resume": resume,
61 "archive-data": archive_data}
46 62
47 63
48def main(args): 64def main(args):
diff --git a/actions/archive-data b/actions/archive-data
new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/actions/archive-data
@@ -0,0 +1 @@
actions.py \ No newline at end of file
diff --git a/hooks/nova_cc_utils.py b/hooks/nova_cc_utils.py
index 7a0749a..4e7cc39 100644
--- a/hooks/nova_cc_utils.py
+++ b/hooks/nova_cc_utils.py
@@ -775,6 +775,24 @@ def map_instances():
775 raise 775 raise
776 776
777 777
778def archive_deleted_rows(max_rows=None):
779 log('Archiving deleted rows', level=INFO)
780 cmd = ['nova-manage', 'db', 'archive_deleted_rows', '--verbose']
781 if max_rows:
782 cmd.extend(['--max_rows', str(max_rows)])
783 process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
784 stdout, stderr = process.communicate()
785 exit_code = process.wait()
786 if exit_code not in [0, 1]:
787 msg = 'Archiving deleted rows failed\nstdout: {}\nstderr: {}'.format(
788 stdout,
789 stderr)
790 log(msg, level=ERROR)
791 raise Exception(msg)
792 else:
793 return stdout
794
795
778def add_hosts_to_cell(): 796def add_hosts_to_cell():
779 '''Map compute hosts to cell''' 797 '''Map compute hosts to cell'''
780 log('Cell1 discover_hosts', level=INFO) 798 log('Cell1 discover_hosts', level=INFO)
diff --git a/unit_tests/test_nova_cc_utils.py b/unit_tests/test_nova_cc_utils.py
index b36b141..9b3149d 100644
--- a/unit_tests/test_nova_cc_utils.py
+++ b/unit_tests/test_nova_cc_utils.py
@@ -1033,6 +1033,37 @@ class NovaCCUtilsTests(CharmTestCase):
1033 'map_instances', '--cell_uuid', 1033 'map_instances', '--cell_uuid',
1034 cell_uuid]) 1034 cell_uuid])
1035 1035
1036 @patch('subprocess.Popen')
1037 def test_archive_deleted_rows(self, mock_popen):
1038 process_mock = MagicMock()
1039 attrs = {
1040 'communicate.return_value': ('output', 'error'),
1041 'wait.return_value': 0}
1042 process_mock.configure_mock(**attrs)
1043 mock_popen.return_value = process_mock
1044 expectd_calls = [
1045 call([
1046 'nova-manage',
1047 'db',
1048 'archive_deleted_rows',
1049 '--verbose'], stdout=-1),
1050 call().communicate(),
1051 call().wait()]
1052
1053 utils.archive_deleted_rows()
1054 self.assertEqual(mock_popen.mock_calls, expectd_calls)
1055
1056 @patch('subprocess.Popen')
1057 def test_archive_deleted_rows_excpetion(self, mock_popen):
1058 process_mock = MagicMock()
1059 attrs = {
1060 'communicate.return_value': ('output', 'error'),
1061 'wait.return_value': 123}
1062 process_mock.configure_mock(**attrs)
1063 mock_popen.return_value = process_mock
1064 with self.assertRaises(Exception):
1065 utils.archive_deleted_rows()
1066
1036 @patch.object(utils, 'get_cell_uuid') 1067 @patch.object(utils, 'get_cell_uuid')
1037 @patch('subprocess.check_output') 1068 @patch('subprocess.check_output')
1038 def test_add_hosts_to_cell(self, mock_check_output, mock_get_cell_uuid): 1069 def test_add_hosts_to_cell(self, mock_check_output, mock_get_cell_uuid):