Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't register new hosts via pxe or api in working-1.6 #548

Open
darksidemilk opened this issue Feb 24, 2023 · 2 comments
Open

Can't register new hosts via pxe or api in working-1.6 #548

darksidemilk opened this issue Feb 24, 2023 · 2 comments
Labels

Comments

@darksidemilk
Copy link
Member

darksidemilk commented Feb 24, 2023

Describe the bug

When attempting to add a new host to fog in 1.6 either through the api or pxe full host registration it fails

To Reproduce

Steps to reproduce the behavior for pxe:

  1. Install or upgrade to fog 1.6
  2. pxe boot to it with an unregistered host (i.e a new vm)
  3. Attempt to do a full host registration and inventory and see the error that your hostname is invalid but this host name displayed isn't what you typed but rather a random string

Steps to reproduce the behavior for pxe:

  1. Install or upgrade to fog 1.6
  2. Submit an api call to create a new host
  3. Get a 500 error in return instead of a success message

Example using fogapi powershell module

install-module fogapi
import-module fogapi
set-fogserversettings -fogapitoken 'server-api-token-here' -fogusertoken 'your-fog-user-token-here' -fogserver 'your-fog-server-hostname-here';
Add-FogHost -name test-host -macs "01:02:03:04:05:06" 

Expected behavior

The host should have been added or registered successfully

Screenshots
If applicable, add screenshots to help explain your problem.

Error on api call
image

Error on full pxe registration

image

Software (please complete the following information):

  • FOG version 1.6
  • FOS kernel 5.15.19
  • OS: Cent OS Stream 9 (Also occurred on Cent OS 7)
  • PHP: Occurs with both 7.4 and 8.0.27

Additional context
Add any other context about the problem here.

It seems to be related to a call to the ishostnamesafe function in the host class.

public function isHostnameSafe($hostname = '')
    {
        if (empty($hostname)) {
            $hostname = $this->get('name');
        }
        $pattern = "/^[\w!@#$%^()\-'{}\.~]{1,15}$/";
        return (bool)preg_match($pattern, $hostname);
    }

if I change this function so it always returns true, then it gets past the error in the pxe host registration

public function isHostnameSafe($hostname = '')
    {
        return true;
        //if (empty($hostname)) {
           // $hostname = $this->get('name');
        //}
        //$pattern = "/^[\w!@#$%^()\-'{}\.~]{1,15}$/";
        //return (bool)preg_match($pattern, $hostname);
    }

But of course, that's not what we want, we want this check to exist.
Also, it does something else weird, it gives it a different name than what I input.
i.e. I input dr-wks-jjv5 as the hostname in the pxe regsitration with the ishostnamesafe set to always return true.
It looks fine in the pxe menu but then the hostname that gets registered is ZHItd2tzLWpqdjUK

image

So something is happening with the input between the registration class fullreg call and when the host is registered.

Changing the return to always true doesn't get past the problem in the api call, so something else is happening with that.

@darksidemilk
Copy link
Member Author

This commit b8e076d appears to have fix pxe registration.

However, in for 1.5.X we can create a fog host via the api with a json like

{
  "name": "someName",
  "macs": [
    "1A:2B:3C:4D:5E:6F"
  ],
  "modules": [
    "4",
    "7",
    "1",
    "3",
    "5",
    "8",
    "9",
    "13",
    "10",
    "6",
    "11",
    "2",
    "12"
  ]
}

Which is the json format created by the fogApi powershell module function New-FogHost

In working-1.6 this json produces a 500 error

However, if you remove the macs array property from the json, it gives an { "error": "Already created" } in the response.
But, it actually does create the host

image

If you hover over that host with no mac (it won't open on click) you can view the url that includes the host id, or using the fogApi ps module you can find the host id in the full list of hosts with get-foghosts | ? name -eq 'someName' | select id

Then you can use the api to add the mac to the host as a primary mac
Add-FogHostMac -hostID (get-foghosts | ? name -eq 'someName').id -primary -macAddress "1A:2B:3C:4D:5E:6F" -vb

This function will given an error saying 404 not found at one point because it tries to get the host record before adding the mac, until the mac is added you can't get the record of the host, only view it in the full list of hosts, same as in the UI. But this does add the mac via the api and
image

However, if you were to add another mac address to that host and mark it as primary too, i.e.
Add-FogHostMac -hostID (get-foghosts | ? name -eq 'someName').id -primary -macAddress "1A:2B:3C:4D:5E:6H"
it creates 2 entries for that host in the hosts view
image

If you click into either it goes to the same place and lists the more recently set as primary mac as the primary mac
image

If you click the 'Primary Mac' selection in the UI, it fixes the duplicated display.
The duplicated display doesn't happen if you add a non-primary mac via the api

A bit hinky, but hopefully that workaround might help @mastacontrola with debugging what's going on.

Short version

  • Host registration now works in pxe but not via api
  • You can create a host with no mac via the api, and then add the mac to it after and this does work
  • If you add a new primary mac via the api, it makes the ui display that host twice until you re-set a primary mac in the ui

@Neustradamus
Copy link

To follow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants