Nailgun DB reset command
Change-Id: I02ba3f086b27c4fe82804bba18596ef095ea7100
This commit is contained in:
parent
a307312bef
commit
f98d3d6a15
|
@ -31,6 +31,18 @@ DOCKER_DEVICEMAPPER_PATH = '/var/lib/docker/devicemapper/mnt/'
|
|||
class DockerMixin(object):
|
||||
container = None
|
||||
|
||||
def container_command(self, *commands):
|
||||
return [
|
||||
#'lxc-attach', '--name', self.get_full_docker_id()
|
||||
'docker', 'exec', self.get_docker_id()
|
||||
] + list(commands)
|
||||
|
||||
def container_command_interactive(self, *commands):
|
||||
return [
|
||||
#'lxc-attach', '--name', self.get_full_docker_id()
|
||||
'docker', 'exec', '-it', self.get_docker_id()
|
||||
] + list(commands)
|
||||
|
||||
def get_container_config(self):
|
||||
d = self.get_container_config_directory()
|
||||
|
||||
|
@ -239,18 +251,6 @@ class ShellCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def container_command(self, *commands):
|
||||
return [
|
||||
#'lxc-attach', '--name', self.get_full_docker_id()
|
||||
'docker', 'exec', self.get_docker_id()
|
||||
] + list(commands)
|
||||
|
||||
def container_command_interactive(self, *commands):
|
||||
return [
|
||||
#'lxc-attach', '--name', self.get_full_docker_id()
|
||||
'docker', 'exec', '-it', self.get_docker_id()
|
||||
] + list(commands)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShellCommand, self).get_parser(prog_name)
|
||||
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from fuel_dev_tools import command
|
||||
from fuel_dev_tools import docker
|
||||
from fuel_dev_tools import info
|
||||
from fuel_dev_tools import ssh
|
||||
|
||||
|
||||
class DockerNailgunMixin(object):
|
||||
|
@ -41,6 +43,45 @@ class Config(DockerNailgunMixin, docker.ConfigCommand):
|
|||
"""Print Docker container config."""
|
||||
|
||||
|
||||
class DBReset(DockerNailgunMixin,
|
||||
docker.DockerMixin,
|
||||
ssh.SSHMixin,
|
||||
command.BaseCommand):
|
||||
"""Reset the whole database to defaults."""
|
||||
def take_action(self, parsed_args):
|
||||
from fuel_dev_tools.docker import postgres
|
||||
|
||||
reset_sql = """
|
||||
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'nailgun';
|
||||
DROP DATABASE nailgun;
|
||||
CREATE DATABASE nailgun WITH OWNER nailgun;
|
||||
"""
|
||||
|
||||
p = postgres.Shell(self.app, self.app_args)
|
||||
|
||||
cmd = [
|
||||
'echo', '"{}"'.format(reset_sql),
|
||||
'> {}/rootfs/tmp/reset-db.sql'.format(p.get_container_directory()),
|
||||
]
|
||||
p.ssh_command(*cmd)
|
||||
|
||||
cmd = p.container_command(
|
||||
'chown', 'postgres:postgres', '/tmp/reset-db.sql'
|
||||
)
|
||||
p.ssh_command(*cmd)
|
||||
|
||||
cmd = p.container_command(
|
||||
'su', '-', 'postgres',
|
||||
'-c', '"cat /tmp/reset-db.sql | psql -d nailgun"'
|
||||
)
|
||||
p.ssh_command(*cmd)
|
||||
|
||||
cmd = self.container_command('manage.py', 'syncdb')
|
||||
p.ssh_command(*cmd)
|
||||
|
||||
cmd = self.container_command('manage.py', 'loaddefault')
|
||||
|
||||
|
||||
class Dir(DockerNailgunMixin, docker.DirCommand):
|
||||
"""Print Docker container directory on master."""
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ COMMANDS = {
|
|||
|
||||
'nailgun-id': nailgun.Id,
|
||||
'nailgun-config': nailgun.Config,
|
||||
'nailgun-db-reset': nailgun.DBReset,
|
||||
'nailgun-dir': nailgun.Dir,
|
||||
'nailgun-log': nailgun.Log,
|
||||
'nailgun-restart': nailgun.Restart,
|
||||
|
|
Loading…
Reference in New Issue