<commit_before># vim: tabstop=4 shiftwidth=4 softtabstop=4

#    Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempfile import TemporaryFile

from devstack import component as comp
from devstack import log as logging
from devstack import shell as sh
from devstack import utils

LOG = logging.getLogger("devstack.components.rabbit")

# Default password (guest)
RESET_BASE_PW = ''

# Config keys we warm up so u won't be prompted later
WARMUP_PWS = ['rabbit']

# Partial of rabbit user prompt
PW_USER_PROMPT = 'the rabbit user'


class RabbitUninstaller(comp.PkgUninstallComponent):
    def __init__(self, *args, **kargs):
        comp.PkgUninstallComponent.__init__(self, *args, **kargs)
        self.runtime = RabbitRuntime(*args, **kargs)
        (runtime_cls, _) = self.distro.extract_component(self.component_name, 'running')
        if not runtime_cls:
            self.runtime = RabbitRuntime(*args, **kargs)
        else:
            self.runtime = runtime_cls(*args, **kargs)

    def pre_uninstall(self):
        try:
            self.runtime.restart()
            LOG.info("Attempting to reset the rabbit-mq guest password to \"%s\"", RESET_BASE_PW)
            cmd = self.distro.get_command('rabbit-mq', 'change_password') + [RESET_BASE_PW]
            sh.execute(*cmd, run_as_root=True)
        except IOError:
            LOG.warn(("Could not reset the rabbit-mq password. You might have to manually "
                      "reset the password to \"%s\" before the next install") % (RESET_BASE_PW))


class RabbitInstaller(comp.PkgInstallComponent):
    def __init__(self, *args, **kargs):
        comp.PkgInstallComponent.__init__(self, *args, **kargs)
        (runtime_cls, _) = self.distro.extract_component(self.component_name, 'running')
        if not runtime_cls:
            self.runtime = RabbitRuntime(*args, **kargs)
        else:
            self.runtime = runtime_cls(*args, **kargs)

    def warm_configs(self):
        for pw_key in WARMUP_PWS:
            self.pw_gen.get_password(pw_key, PW_USER_PROMPT)

    def _setup_pw(self):
        LOG.info("Setting up your rabbit-mq guest password.")
        self.runtime.restart()
        passwd = self.pw_gen.get_password("<PASSWORD>", PW_USER_PROMPT)
        cmd = self.distro.get_command('rabbit-mq', 'change_password') + [passwd]
        sh.execute(*cmd, run_as_root=True)
        LOG.info("Restarting so that your rabbit-mq guest password is reflected.")<commit_msg>String fixups<commit_after># vim: tabstop=4 shiftwidth=4 softtabstop=4

#    Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempfile import TemporaryFile

from devstack import component as comp
from devstack import log as logging
from devstack import shell as sh
from devstack import utils

LOG = logging.getLogger("devstack.components.rabbit")

# Default password (guest)
RESET_BASE_PW = ''

# Config keys we warm up so u won't be prompted later
WARMUP_PWS = ['rabbit']

# Partial of rabbit user prompt
PW_USER_PROMPT = 'the rabbit user'


class RabbitUninstaller(comp.PkgUninstallComponent):
    def __init__(self, *args, **kargs):
        comp.PkgUninstallComponent.__init__(self, *args, **kargs)
        self.runtime = RabbitRuntime(*args, **kargs)
        (runtime_cls, _) = self.distro.extract_component(self.component_name, 'running')
        if not runtime_cls:
            self.runtime = RabbitRuntime(*args, **kargs)
        else:
            self.runtime = runtime_cls(*args, **kargs)

    def pre_uninstall(self):
        try:
            self.runtime.restart()
            LOG.info("Attempting to reset the rabbit-mq guest password to %r", RESET_BASE_PW)
            cmd = self.distro.get_command('rabbit-mq', 'change_password') + [RESET_BASE_PW]
            sh.execute(*cmd, run_as_root=True)
        except IOError:
            LOG.warn(("Could not reset the rabbit-mq password. You might have to manually "
                      "reset the password to %r before the next install") % (RESET_BASE_PW))


class RabbitInstaller(comp.PkgInstallComponent):
    def __init__(self, *args, **kargs):
        comp.PkgInstallComponent.__init__(self, *args, **kargs)
        (runtime_cls, _) = self.distro.extract_component(self.component_name, 'running')
        if not runtime_cls:
            self.runtime = RabbitRuntime(*args, **kargs)
        else:
            self.runtime = runtime_cls(*args, **kargs)

    def warm_configs(self):
        for pw_key in WARMUP_PWS:
            self.pw_gen.get_password(pw_key, PW_USER_PROMPT)

    def _setup_pw(self):
        LOG.info("Setting up your rabbit-mq guest password.")
        self.runtime.restart()
        passwd = self.pw_gen.get_password("<PASSWORD>", PW_USER_PROMPT)
        cmd = self.distro.get_command('rabbit-mq', 'change_password') + [passwd]
        sh.execute(*cmd, run_as_root=True)
        LOG.info("Restarting so that your rabbit-mq guest password is reflected.")
{'fraction_non_alphanumeric': 0.09953703703703703, 'fraction_numerical': 0.0036375661375661374, 'mean_word_length': 3.1717241379310344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3924666', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1764, 'n_words': 540}