Beispiel #1
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()
Beispiel #2
0
 def test_get_fqdns_by_roles(self):
     nova_api = RoleDescription.get_by_name('OpenStack Compute API')
     composition = nova_api.get_composition()
     node = self._add_dummy_node_into_role('node_1234', composition)
     nodes = Node.get_fqdns_by_roles(composition)
     self.assertEqual(node.fqdn, nodes[0])
     self.assertEqual(len(nodes), 1)
Beispiel #3
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')
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
0
 def test_get_fqdns_by_roles_with_disabled(self):
     nova_api = RoleDescription.get_by_name('OpenStack Compute API')
     composition = nova_api.get_composition()
     self._add_dummy_node_into_role('node_1234',
                                    composition,
                                    is_enabled=False)
     self._add_dummy_node_into_role('node_1235', composition)
     all_apis = Node.get_fqdns_by_roles(composition)
     self.assertListEqual(['node_1235'], all_apis)
Beispiel #7
0
 def test_get_fqdns_exclude_by_roles(self):
     self._add_dummy_node_into_role('test1', [Role.OPENSTACK_DASHBOARD,
                                              Role.NOVA_API])
     self._add_dummy_node_into_role('test2', [Role.NOVA_COMPUTE,
                                              Role.NOVA_NETWORK])
     self._add_dummy_node_into_role('test3', [Role.SWIFT_ACCOUNT,
                                              Role.SWIFT_OBJECT])
     node_fqdns = Node.get_fqdns_excluded_by_roles([Role.NOVA_COMPUTE])
     self.assertListEqual(['test1', 'test3'], node_fqdns)
Beispiel #8
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
Beispiel #9
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")
Beispiel #10
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)
Beispiel #11
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
Beispiel #12
0
    def _add_dummy_node(self, fqdn='test_fqdn', is_enabled=True):
        self.dummy_node_fqdn = fqdn
        node = Node.create(fqdn)
        node.enabled = is_enabled
        import pickle
        node.facts = pickle.dumps({
            "geppetto_status_running_services":
            "openstack-nova-api,openstack-nova-compute",
            "geppetto_status_stopped_services": "openstack-nova-network",
            "host_fqdn": "test_host",
            "ipaddress_eth0": "169.254.0.2",
            "ipaddress_eth1": "127.0.0.1",
            "interfaces": "'eth0,eth1,eth2,lo'",
        })
        node.save()
        node.joined_date = datetime.datetime(2001, 1, 1, 0, 0, 0, 0)

        # make the host guid predictable
        param = ConfigClassParameter.get_by_name(
            ConfigClassParameter.HOST_GUID)
        Override.update_or_create_override(node, param, "00:00:00:00:00:00")

        return node
Beispiel #13
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)
Beispiel #14
0
 def _add_blank_node(self, node_fqdn='test_fqdn'):
     node = Node(fqdn=node_fqdn, master=Master.objects.all()[0])
     node.save()
     return node
Beispiel #15
0
 def test_safe_get_by_name(self):
     node = Node.safe_get_by_name('missing_node')
     self.assertEqual(node, None)
Beispiel #16
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))
Beispiel #17
0
 def test_get_all_with_disabled(self):
     self._add_dummy_node('n1', False)
     self._add_dummy_node('n2')
     all = Node.get_fqdns()
     self.assertListEqual(['n2'], all)