#
# Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
#

import subprocess


class CassandraManager(object):
    def __init__(self, cassandra_repair_logdir):
        self.cassandra_repair_logdir = cassandra_repair_logdir

    def status(self):
        subprocess.Popen(["contrail-cassandra-status",
                          "--log-file", "/var/log/cassandra/status.log",
                          "--debug"])

    def repair(self):
        logdir = self.cassandra_repair_logdir + "repair.log"
        subprocess.Popen(["contrail-cassandra-repair",
                          "--log-file", logdir,
                          "--debug"])

#
# Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
#

import subprocess


class CassandraManager(object):
    def __init__(self, cassandra_repair_logdir):
        self.cassandra_repair_logdir = cassandra_repair_logdir

    def status(self):
        subprocess.Popen(["contrail-cassandra-status",
                          "--log-file", "/var/log/cassandra/status.log",
                          "--debug"], close_fds=True)

    def repair(self):
        logdir = self.cassandra_repair_logdir + "repair.log"
        subprocess.Popen(["contrail-cassandra-repair",
                          "--log-file", logdir,
                          "--debug"], close_fds=True)

Fix issue with config-nodemgr and cassandra-repair listening on same port
Fix issue with config-nodemgr and cassandra-repair listening on same port

contrail-config-nodemgr spawns contrail-cassandra-repair using
subprocess.Popen and thus contrail-cassandra-repair inherits all
the fds including the listening fd. Then when contrail-config-nodemgr
is restarted/killed, contrail-cassandra-repair will still have the
listening fd and hence contrail-config-nodemgr will not be able to
come up and listen on the same port. Fix is to use - close_fds=True
in the Popen call since the parent and child don't really need to
communicate or share anything using fds and this will close all the
fds shared from parent in the child.

Change-Id: Icef9f981c6447dd013cebeab727f49c5e2cf74f8
Closes-Bug: #1643466
