Esempio n. 1
0
def assign_and_configure_roles_to_node(node_fqdn, role_list, node_config=None):
    node = Node.get_by_name(node_fqdn)
    if node_config != None:
        for param_label, value in node_config.iteritems():
            param = ConfigClassParameter.get_by_name(param_label)
            Override.update_or_create_override(node, param, value)
    roles = [Role.get_by_name(role_name) for role_name in role_list]
    NodeRoleAssignment.add_roles_to_node(node, roles, True)
Esempio n. 2
0
 def testSimpleReport(self):
     self._add_dummy_node('test_node')
     report_service.process_report(self)
     node = Node.get_by_name('test_node')
     self.assertEqual(node.report_status, ReportStatus.Changed)
     self.assertEqual(node.report_date, datetime.datetime(2001, 1, 1,
                                                          0, 0, 0, 0))
     self.assertEqual(node.report_log, u'Puppet: FAKE LOG')
Esempio n. 3
0
 def test_delete_roles(self):
     nova_api = RoleDescription.get_by_name('OpenStack Compute API')
     composition = nova_api.get_composition()
     self._add_dummy_node_into_role('node_1234',
                                    composition + DEFAULT_ROLES)
     node = Node.get_by_name('node_1234')
     node.delete_roles()
     roles = [r.name for r in node.get_roles()]
     self.assertListEqual(DEFAULT_ROLES, roles)
Esempio n. 4
0
def process_report(request):
    """This function is called by the puppetmaster's reporting system."""
    node = None
    try:
        report_details = parse_node_report(request.raw_post_data)
        node = Node.get_by_name(report_details['node_fqdn'])
        node.set_report(report_details)
        return HttpResponse(report_details['node_fqdn'], mimetype="text/plain")
    except Exception, e:
        logger.exception(e)
        return HttpResponse(str(e), status=500, mimetype="text/plain")
Esempio n. 5
0
def update_related_config_params(roles, node_fqdn):
    """Update all config values affected by the given worker type moving
    to a new node. Then restart all affected services.
    """
    affected_config_parms = []
    for role in roles:
        if role.description:
            affected_config_parms.extend(RoleDesConfigParamAssignment.\
                            get_param_labels_by_description(role.description))
    affected_config_parms = set(affected_config_parms)

    for param_label in affected_config_parms:
        ConfigClassParameter.set_config_parameter(param_label, node_fqdn)
        Override.update_overrides(ConfigClassParameter.\
                                                get_by_name(param_label))
        GroupOverride.update_overrides(ConfigClassParameter.\
                                                get_by_name(param_label))

    # restart appropriate services on the affected nodes or
    # track nodes whose CLI configuration require a refresh
    node_dict = {}
    details = ConfigClassParameter.\
                            get_details_for_params(affected_config_parms)
    for param_label in affected_config_parms:
        applies_to = details[param_label]['applies-to']
        for role_name in applies_to:
            role_name = str(role_name)
            affected_nodes = Node.get_fqdns_by_role(role_name)
            for n in affected_nodes:
                if n in node_dict and role_name not in node_dict[n]:
                    node_dict[n].append(role_name)
                elif n != node_fqdn:
                    node_dict[n] = [role_name]
            affected_nodes = Node.get_fqdns_by_role(role_name,
                                                    is_service=False)
            for n in affected_nodes:
                if n not in node_dict:
                    node_dict[n] = []

    svc_restart = ConfigClassParameter.\
                get_by_name(ConfigClassParameter.VPX_RESTART_SERVICES)
    for node_fqdn, role_to_restart in node_dict.iteritems():
        if len(role_to_restart) > 0:
            Override.update_or_create_override(Node.get_by_name(node_fqdn),
                                               svc_restart, role_to_restart,
                                               True)

    return node_dict.keys()
Esempio n. 6
0
 def process_facts(self, node_fqdn, facts):
     """This function is called by the puppetmaster's reporting system."""
     node = None
     try:
         node = Node.get_by_name(node_fqdn)
         node.set_facts(parse_node_facts(facts))
         auth_status = node.is_authenticated()
         if auth_status is None:
             logger.warning("(%s): Unable to get facts: not "
                            "authenticated." % node_fqdn)
         elif auth_status is False:
             logger.warning("(%s): Unable to get facts: bad "
                            "credentials." % node_fqdn)
     except Failure, e:
         # get_by_name must have raised a not_found exception.
         logger.warning('%s: waiting for the node to register.' % node_fqdn)
Esempio n. 7
0
def get_or_create_node(node_fqdn):
    try:
        node = Node.get_by_name(node_fqdn)
    except:
        node = Node.create(node_fqdn)
        # Generate and assign a Host GUID
        host_guid = _generate_host_guid()
        param = ConfigClassParameter.get_by_name(
            ConfigClassParameter.HOST_GUID)
        Override.update_or_create_override(node, param, host_guid)
        # Assign default roles on node creation
        default_roles = Role.get_default_roles()
        NodeRoleAssignment.add_roles_to_node(node, default_roles)
        # determine if we can add celeryd on each worker. This is
        # possible only if the DB backend is != sqlite3
        if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql':
            celery_role = Role.get_by_name(Role.CELERY_WORKER)
            NodeRoleAssignment.add_roles_to_node(node, [celery_role], True)
    return node
Esempio n. 8
0
def create_swift_rings(hostnames):
    """This attempts to create the swift ring file on the master,
    given the specified hostnames of the swift object nodes."""
    # Resolve IPs
    # TODO - we should have this info in the facts
    ips = []
    for hostname in hostnames:
        ips.append(socket.gethostbyname(hostname))
    ips_str = string.join(ips, " ")

    # Assign Ring Builder Role: runs on this host
    node_fqdn = network.get_hostname()
    node = Node.get_by_name(node_fqdn)

    Override.update_or_create_override(
        node,
        ConfigClassParameter.get_by_name(ConfigClassParameter.SWIFT_NODES_IPS),
        ips_str)
    NodeRoleAssignment.add_roles_to_node(node,
                                         [Role.get_by_name(Role.RING_BUILDER)],
                                         True)
    return node_fqdn
Esempio n. 9
0
 def test_delete_overrides(self):
     self._add_dummy_override('node_1234')
     node = Node.get_by_name('node_1234')
     node.delete_overrides()
     overrides = node.get_overrides_dict()
     self.assertDictEqual({}, overrides)
Esempio n. 10
0
    def tearDown(self):
        super(TestPuppetServices, self).tearDown()
        self.stubs.UnsetAll()

    def testSimpleReport(self):
        self._add_dummy_node('test_node')
        report_service.process_report(self)
        node = Node.get_by_name('test_node')
        self.assertEqual(node.report_status, ReportStatus.Changed)
        self.assertEqual(node.report_date, datetime.datetime(2001, 1, 1,
                                                             0, 0, 0, 0))
        self.assertEqual(node.report_log, u'Puppet: FAKE LOG')

    def testSimpleFacts(self):
        self.expected_facts = {'host_fqdn': 'host_fqdn1232131',
                               'host_ip': '10.219.13.20',
                               'host_local_storage_size': 237568532480L,
                               'host_local_storage_utilisation': 4657770496L,
                               'host_memory_free': 22468952064L,
                               'host_memory_total': 25759420416L,
                               'host_password_status': 'SET',
                               'host_type': 'xenapi', }

        self._add_dummy_node('test_node')
        svc = facter_service.Service()
        svc.process_facts('test_node', self.node_facts)
        node = Node.get_by_name('test_node')
        for fact_key, fact_value in self.expected_facts.items():
            self.assertEqual(fact_value, node.get_fact(fact_key))