Skip to content

Commit 9c0d661

Browse files
committed
Merge branch 'master' into remove_td_agent
2 parents fbfaefb + 5c2616d commit 9c0d661

File tree

4 files changed

+143
-1
lines changed

4 files changed

+143
-1
lines changed

dbaas/logical/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def delete(self, *args, **kwargs):
175175
else:
176176
LOG.warning("Putting database {} in quarantine".format(self.name))
177177
self.is_in_quarantine = True
178+
self.is_protected = False
178179
self.save()
179180
if self.credentials.exists():
180181
for credential in self.credentials.all():
@@ -554,7 +555,7 @@ def can_be_cloned(self):
554555

555556
def can_be_deleted(self):
556557
error = None
557-
if self.is_protected:
558+
if self.is_protected and not self.is_in_quarantine:
558559
error = "Database {} is protected and cannot be deleted"
559560
elif self.is_dead:
560561
error = "Database {} is not alive and cannot be deleted"

dbaas/logical/tests/test_database.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"Database does not have persistence cannot be cloned"
1818
ERROR_CLONE_IN_QUARANTINE = "Database in quarantine cannot be cloned"
1919
ERROR_CLONE_NOT_ALIVE = "Database is not alive and cannot be cloned"
20+
ERROR_DELETE_PROTECTED = "Database {} is protected and cannot be deleted"
21+
ERROR_DELETE_DEAD = "Database {} is not alive and cannot be deleted"
2022

2123

2224
class FakeDriver(base.BaseDriver):
@@ -174,6 +176,50 @@ def test_cannot_clone_dead(self):
174176
self.assertFalse(can_be_cloned)
175177
self.assertEqual(error, ERROR_CLONE_NOT_ALIVE)
176178

179+
def test_can_delete(self):
180+
database = factory.DatabaseFactory()
181+
database.status = database.ALIVE
182+
183+
can_be_deleted, error = database.can_be_deleted()
184+
self.assertTrue(can_be_deleted)
185+
self.assertIsNone(error)
186+
187+
def test_cannot_delete_protected(self):
188+
database = factory.DatabaseFactory()
189+
database.status = database.ALIVE
190+
database.is_protected = True
191+
192+
can_be_deleted, error = database.can_be_deleted()
193+
self.assertFalse(can_be_deleted)
194+
self.assertEqual(error, ERROR_DELETE_PROTECTED.format(database.name))
195+
196+
def test_can_delete_protected_in_quarantine(self):
197+
database = factory.DatabaseFactory()
198+
database.status = database.ALIVE
199+
database.is_protected = True
200+
database.is_in_quarantine = True
201+
202+
can_be_deleted, error = database.can_be_deleted()
203+
self.assertTrue(can_be_deleted)
204+
self.assertIsNone(error)
205+
206+
def test_can_delete_in_quarantine(self):
207+
database = factory.DatabaseFactory()
208+
database.status = database.ALIVE
209+
database.is_in_quarantine = True
210+
211+
can_be_deleted, error = database.can_be_deleted()
212+
self.assertTrue(can_be_deleted)
213+
self.assertIsNone(error)
214+
215+
def test_cannot_delete_dead(self):
216+
database = factory.DatabaseFactory()
217+
database.status = database.DEAD
218+
219+
can_be_deleted, error = database.can_be_deleted()
220+
self.assertFalse(can_be_deleted)
221+
self.assertEqual(error, ERROR_DELETE_DEAD.format(database.name))
222+
177223
'''
178224
179225
@mock.patch.object(clone_database, 'delay')

dbaas/workflow/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'workflow.steps.mysql.flipperfox_migration.check_pupet.CheckPuppetIsRunning',
4040
'workflow.steps.mysql.flipperfox_migration.config_vms_foreman.ConfigVMsForeman',
4141
'workflow.steps.mysql.flipperfox_migration.run_pupet_setup.RunPuppetSetup',
42+
'workflow.steps.mysql.flipperfox_migration.config_log.ConfigLog',
4243
'workflow.steps.mysql.flipperfox_migration.config_fox.ConfigFox',
4344
'workflow.steps.mysql.flipperfox_migration.create_foxha_mysql_users.CreateFoxHAMySQLUser',
4445
'workflow.steps.mysql.flipperfox_migration.config_backup_log.ConfigBackupLog',
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- coding: utf-8 -*-
2+
import logging
3+
from util import full_stack
4+
from util import exec_remote_command
5+
from dbaas_cloudstack.models import HostAttr as CS_HostAttr
6+
from workflow.steps.util.base import BaseStep
7+
from workflow.exceptions.error_codes import DBAAS_0020
8+
9+
LOG = logging.getLogger(__name__)
10+
11+
12+
class ConfigLog(BaseStep):
13+
14+
def __unicode__(self):
15+
return "Configuring rsyslog..."
16+
17+
def do(self, workflow_dict):
18+
try:
19+
for source_host in workflow_dict['source_hosts']:
20+
future_host = source_host.future_host
21+
cs_host_attr = CS_HostAttr.objects.get(host=future_host)
22+
23+
LOG.info("Configuring rsyslog {}".format(future_host))
24+
25+
script = self.rsyslog_create_config(workflow_dict['database'])
26+
LOG.info(script)
27+
28+
output = {}
29+
return_code = exec_remote_command(
30+
server=future_host.address,
31+
username=cs_host_attr.vm_user,
32+
password=cs_host_attr.vm_password,
33+
command=script,
34+
output=output
35+
)
36+
LOG.info(output)
37+
if return_code != 0:
38+
error_msg = "Error configuring rsyslog: {}".format(str(output))
39+
LOG.error(error_msg)
40+
raise EnvironmentError(error_msg)
41+
42+
return True
43+
except Exception:
44+
traceback = full_stack()
45+
46+
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
47+
workflow_dict['exceptions']['traceback'].append(traceback)
48+
49+
return False
50+
51+
def undo(self, workflow_dict):
52+
LOG.info("Running undo...")
53+
try:
54+
for source_host in workflow_dict['source_hosts']:
55+
future_host = source_host.future_host
56+
cs_host_attr = CS_HostAttr.objects.get(host=future_host)
57+
58+
LOG.info("Removing rsyslog config in {}".format(future_host))
59+
60+
script = self.rsyslog_remove_config()
61+
LOG.info(script)
62+
63+
output = {}
64+
return_code = exec_remote_command(
65+
server=future_host.address,
66+
username=cs_host_attr.vm_user,
67+
password=cs_host_attr.vm_password,
68+
command=script,
69+
output=output
70+
)
71+
LOG.info(output)
72+
if return_code != 0:
73+
error_msg = "Error removing configuring rsyslog: {}".format(str(output))
74+
LOG.error(error_msg)
75+
raise EnvironmentError(error_msg)
76+
77+
return True
78+
except Exception:
79+
traceback = full_stack()
80+
81+
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
82+
workflow_dict['exceptions']['traceback'].append(traceback)
83+
84+
return False
85+
86+
def rsyslog_create_config(self, database):
87+
return \
88+
' echo "\$EscapeControlCharactersOnReceive off" >> /etc/rsyslog.d/globologging.conf &&' \
89+
' sed -i "\$a \$template db-log, \\\"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg% tags: dbaas,{}\\\"" /etc/rsyslog.d/globologging.conf &&' \
90+
' sed -i "\$a*.* @logging.udp.globoi.com:5140; db-log" /etc/rsyslog.d/globologging.conf &&' \
91+
' /etc/init.d/rsyslog restart'.format(database.name)
92+
93+
def rsyslog_remove_config(self):
94+
return 'rm -f /etc/rsyslog.d/globologging.conf'

0 commit comments

Comments
 (0)