github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetalintrospection/v1/introspection/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/gophercloud/gophercloud"
    10  	"github.com/gophercloud/gophercloud/openstack/baremetalintrospection/v1/introspection"
    11  	th "github.com/gophercloud/gophercloud/testhelper"
    12  	"github.com/gophercloud/gophercloud/testhelper/client"
    13  )
    14  
    15  // IntrospectionListBody contains the canned body of a introspection.IntrospectionList response.
    16  const IntrospectionListBody = `
    17  {
    18    "introspection": [
    19      {
    20        "error": null,
    21        "finished": true,
    22        "finished_at": "2017-08-17T11:36:16",
    23        "links": [
    24          {
    25            "href": "http://127.0.0.1:5050/v1/introspection/05ccda19-581b-49bf-8f5a-6ded99701d87",
    26            "rel": "self"
    27          }
    28        ],
    29        "started_at": "2017-08-17T11:33:43",
    30        "state": "finished",
    31        "uuid": "05ccda19-581b-49bf-8f5a-6ded99701d87"
    32      },
    33      {
    34        "error": null,
    35        "finished": true,
    36        "finished_at": "2017-08-16T12:24:30",
    37        "links": [
    38          {
    39            "href": "http://127.0.0.1:5050/v1/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b",
    40            "rel": "self"
    41          }
    42        ],
    43        "started_at": "2017-08-16T12:22:01",
    44        "state": "finished",
    45        "uuid": "c244557e-899f-46fa-a1ff-5b2c6718616b"
    46      }
    47    ]
    48  }
    49  `
    50  
    51  // IntrospectionStatus contains the respnse of a single introspection satus.
    52  const IntrospectionStatus = `
    53  {
    54    "error": null,
    55    "finished": true,
    56    "finished_at": "2017-08-16T12:24:30",
    57    "links": [
    58      {
    59        "href": "http://127.0.0.1:5050/v1/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b",
    60        "rel": "self"
    61      }
    62    ],
    63    "started_at": "2017-08-16T12:22:01",
    64    "state": "finished",
    65    "uuid": "c244557e-899f-46fa-a1ff-5b2c6718616b"
    66  }
    67  `
    68  
    69  // IntrospectionDataJSONSample contains sample data reported by the introspection process.
    70  const IntrospectionDataJSONSample = `
    71  {
    72      "all_interfaces": {
    73          "eth0": {
    74              "client_id": null,
    75              "ip": "172.24.42.100",
    76              "lldp_processed": {
    77                  "switch_chassis_id": "11:22:33:aa:bb:cc",
    78                  "switch_system_name": "sw01-dist-1b-b12"
    79              },
    80              "mac": "52:54:00:4e:3d:30",
    81              "pxe": true
    82          },
    83          "eth1": {
    84              "client_id": null,
    85              "ip": "172.24.42.101",
    86              "mac": "52:54:00:47:20:4d",
    87              "pxe": false
    88          }
    89      },
    90      "boot_interface": "52:54:00:4e:3d:30",
    91      "cpu_arch": "x86_64",
    92      "cpus": 2,
    93      "error": null,
    94      "interfaces": {
    95          "eth0": {
    96              "client_id": null,
    97              "ip": "172.24.42.100",
    98              "mac": "52:54:00:4e:3d:30",
    99              "pxe": true
   100          }
   101      },
   102      "inventory": {
   103          "bmc_address": "192.167.2.134",
   104          "boot": {
   105              "current_boot_mode": "bios",
   106              "pxe_interface": "52:54:00:4e:3d:30"
   107          },
   108          "cpu": {
   109              "architecture": "x86_64",
   110              "count": 2,
   111              "flags": [
   112                  "fpu",
   113                  "mmx",
   114                  "fxsr",
   115                  "sse",
   116                  "sse2"
   117              ],
   118              "frequency": "2100.084"
   119          },
   120          "disks": [
   121              {
   122                  "hctl": null,
   123                  "model": "",
   124                  "name": "/dev/vda",
   125                  "rotational": true,
   126                  "serial": null,
   127                  "size": 13958643712,
   128                  "vendor": "0x1af4",
   129                  "wwn": null,
   130                  "wwn_vendor_extension": null,
   131                  "wwn_with_extension": null
   132              }
   133          ],
   134          "hostname": "myawesomehost",
   135          "interfaces": [
   136              {
   137                  "client_id": null,
   138                  "has_carrier": true,
   139                  "ipv4_address": "172.24.42.101",
   140                  "lldp": [],
   141                  "mac_address": "52:54:00:47:20:4d",
   142                  "name": "eth1",
   143                  "product": "0x0001",
   144                  "vendor": "0x1af4"
   145              },
   146              {
   147                  "client_id": null,
   148                  "has_carrier": true,
   149                  "ipv4_address": "172.24.42.100",
   150                  "lldp": [
   151                      [
   152                          1,
   153                          "04112233aabbcc"
   154                      ],
   155                      [
   156                          5,
   157                          "737730312d646973742d31622d623132"
   158                      ]
   159                  ],
   160                  "mac_address": "52:54:00:4e:3d:30",
   161                  "name": "eth0",
   162                  "product": "0x0001",
   163                  "vendor": "0x1af4",
   164  		"speed_mbps": 1000
   165              }
   166          ],
   167          "memory": {
   168              "physical_mb": 2048,
   169              "total": 2105864192
   170          },
   171          "system_vendor": {
   172              "manufacturer": "Bochs",
   173              "product_name": "Bochs",
   174              "serial_number": "Not Specified",
   175  	    "firmware": {
   176  		"version": "1.2.3.4"
   177  	    }
   178          }
   179      },
   180      "ipmi_address": "192.167.2.134",
   181      "lldp_raw": {
   182  	"eth0": [
   183  	    [
   184  		1,
   185  		"04112233aabbcc"
   186  	    ],
   187  	    [
   188  		5,
   189  		"737730312d646973742d31622d623132"
   190  	    ]
   191  	]
   192      },
   193      "local_gb": 12,
   194      "macs": [
   195          "52:54:00:4e:3d:30"
   196      ],
   197      "memory_mb": 2048,
   198      "root_disk": {
   199          "hctl": null,
   200          "model": "",
   201          "name": "/dev/vda",
   202          "rotational": true,
   203          "serial": null,
   204          "size": 13958643712,
   205          "vendor": "0x1af4",
   206          "wwn": null,
   207          "wwn_vendor_extension": null,
   208          "wwn_with_extension": null
   209      }
   210  }
   211  `
   212  
   213  // IntrospectionExtraHardwareJSONSample contains extra hardware sample data
   214  // reported by the introspection process.
   215  const IntrospectionExtraHardwareJSONSample = `
   216  {
   217    "cpu": {
   218      "logical": {
   219        "number": 16
   220      },
   221      "physical": {
   222        "clock": 2105032704,
   223        "cores": 8,
   224        "flags": "lm fpu fpu_exception wp vme de"
   225      }
   226    },
   227    "disk": {
   228      "sda": {
   229        "rotational": 1,
   230        "vendor": "TEST"
   231      }
   232    },
   233    "firmware": {
   234      "bios": {
   235        "date": "01/01/1970",
   236        "vendor": "test"
   237      }
   238    },
   239    "ipmi": {
   240      "Fan1A RPM": {
   241        "unit": "RPM",
   242        "value": 3120
   243      },
   244      "Fan1B RPM": {
   245        "unit": "RPM",
   246        "value": 2280
   247      }
   248    },
   249    "memory": {
   250      "bank0": {
   251        "clock": 1600000000.0,
   252        "description": "DIMM DDR3 Synchronous Registered (Buffered) 1600 MHz (0.6 ns)"
   253      },
   254      "bank1": {
   255        "clock": 1600000000.0,
   256        "description": "DIMM DDR3 Synchronous Registered (Buffered) 1600 MHz (0.6 ns)"
   257      }
   258    },
   259    "network": {
   260      "em1": {
   261        "Autonegotiate": "on",
   262        "loopback": "off [fixed]"
   263      },
   264      "p2p1": {
   265        "Autonegotiate": "on",
   266        "loopback": "off [fixed]"
   267      }
   268    },
   269    "system": {
   270      "ipmi": {
   271        "channel": 1
   272      },
   273      "kernel": {
   274        "arch": "x86_64",
   275        "version": "3.10.0"
   276      },
   277      "motherboard": {
   278        "vendor": "Test"
   279      },
   280      "product": {
   281        "name": "test",
   282        "vendor": "Test"
   283      }
   284    }
   285  }
   286  `
   287  
   288  // IntrospectionNUMADataJSONSample contains NUMA sample data
   289  // reported by the introspection process.
   290  const IntrospectionNUMADataJSONSample = `
   291  {
   292    "numa_topology": {
   293      "cpus": [
   294        {
   295          "cpu": 6,
   296          "numa_node": 1,
   297          "thread_siblings": [
   298            3,
   299            27
   300          ]
   301        },
   302        {
   303          "cpu": 10,
   304          "numa_node": 0,
   305          "thread_siblings": [
   306            20,
   307            44
   308          ]
   309        }
   310      ],
   311      "nics": [
   312        {
   313          "name": "p2p1",
   314          "numa_node": 0
   315        },
   316        {
   317          "name": "p2p2",
   318          "numa_node": 1
   319        }
   320      ],
   321      "ram": [
   322        {
   323          "numa_node": 0,
   324          "size_kb": 99289532
   325        },
   326        {
   327          "numa_node": 1,
   328          "size_kb": 100663296
   329        }
   330      ]
   331    }
   332  }
   333  `
   334  
   335  var (
   336  	fooTimeStarted, _  = time.Parse(gophercloud.RFC3339NoZ, "2017-08-17T11:33:43")
   337  	fooTimeFinished, _ = time.Parse(gophercloud.RFC3339NoZ, "2017-08-17T11:36:16")
   338  	IntrospectionFoo   = introspection.Introspection{
   339  		Finished:   true,
   340  		State:      "finished",
   341  		Error:      "",
   342  		UUID:       "05ccda19-581b-49bf-8f5a-6ded99701d87",
   343  		StartedAt:  fooTimeStarted,
   344  		FinishedAt: fooTimeFinished,
   345  		Links: []interface{}{
   346  			map[string]interface{}{
   347  				"href": "http://127.0.0.1:5050/v1/introspection/05ccda19-581b-49bf-8f5a-6ded99701d87",
   348  				"rel":  "self",
   349  			},
   350  		},
   351  	}
   352  
   353  	barTimeStarted, _  = time.Parse(gophercloud.RFC3339NoZ, "2017-08-16T12:22:01")
   354  	barTimeFinished, _ = time.Parse(gophercloud.RFC3339NoZ, "2017-08-16T12:24:30")
   355  	IntrospectionBar   = introspection.Introspection{
   356  		Finished:   true,
   357  		State:      "finished",
   358  		Error:      "",
   359  		UUID:       "c244557e-899f-46fa-a1ff-5b2c6718616b",
   360  		StartedAt:  barTimeStarted,
   361  		FinishedAt: barTimeFinished,
   362  		Links: []interface{}{
   363  			map[string]interface{}{
   364  				"href": "http://127.0.0.1:5050/v1/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b",
   365  				"rel":  "self",
   366  			},
   367  		},
   368  	}
   369  
   370  	IntrospectionDataRes = introspection.Data{
   371  		CPUArch: "x86_64",
   372  		MACs:    []string{"52:54:00:4e:3d:30"},
   373  		RootDisk: introspection.RootDiskType{
   374  			Rotational: true,
   375  			Model:      "",
   376  			Name:       "/dev/vda",
   377  			Size:       13958643712,
   378  			Vendor:     "0x1af4",
   379  		},
   380  		Interfaces: map[string]introspection.BaseInterfaceType{
   381  			"eth0": {
   382  				IP:  "172.24.42.100",
   383  				MAC: "52:54:00:4e:3d:30",
   384  				PXE: true,
   385  			},
   386  		},
   387  		CPUs:          2,
   388  		BootInterface: "52:54:00:4e:3d:30",
   389  		MemoryMB:      2048,
   390  		IPMIAddress:   "192.167.2.134",
   391  		Inventory: introspection.InventoryType{
   392  			SystemVendor: introspection.SystemVendorType{
   393  				Manufacturer: "Bochs",
   394  				ProductName:  "Bochs",
   395  				SerialNumber: "Not Specified",
   396  				Firmware: introspection.SystemFirmwareType{
   397  					Version: "1.2.3.4",
   398  				},
   399  			},
   400  			BmcAddress: "192.167.2.134",
   401  			Boot: introspection.BootInfoType{
   402  				CurrentBootMode: "bios",
   403  				PXEInterface:    "52:54:00:4e:3d:30",
   404  			},
   405  			CPU: introspection.CPUType{
   406  				Count:        2,
   407  				Flags:        []string{"fpu", "mmx", "fxsr", "sse", "sse2"},
   408  				Frequency:    "2100.084",
   409  				Architecture: "x86_64",
   410  			},
   411  			Disks: []introspection.RootDiskType{
   412  				{
   413  					Rotational: true,
   414  					Model:      "",
   415  					Name:       "/dev/vda",
   416  					Size:       13958643712,
   417  					Vendor:     "0x1af4",
   418  				},
   419  			},
   420  			Interfaces: []introspection.InterfaceType{
   421  				{
   422  					Vendor:      "0x1af4",
   423  					HasCarrier:  true,
   424  					MACAddress:  "52:54:00:47:20:4d",
   425  					Name:        "eth1",
   426  					Product:     "0x0001",
   427  					IPV4Address: "172.24.42.101",
   428  					LLDP:        []introspection.LLDPTLVType{},
   429  				},
   430  				{
   431  					IPV4Address: "172.24.42.100",
   432  					MACAddress:  "52:54:00:4e:3d:30",
   433  					Name:        "eth0",
   434  					Product:     "0x0001",
   435  					HasCarrier:  true,
   436  					Vendor:      "0x1af4",
   437  					LLDP: []introspection.LLDPTLVType{
   438  						{
   439  							Type:  1,
   440  							Value: "04112233aabbcc",
   441  						},
   442  						{
   443  							Type:  5,
   444  							Value: "737730312d646973742d31622d623132",
   445  						},
   446  					},
   447  					SpeedMbps: 1000,
   448  				},
   449  			},
   450  			Memory: introspection.MemoryType{
   451  				PhysicalMb: 2048.0,
   452  				Total:      2.105864192e+09,
   453  			},
   454  			Hostname: "myawesomehost",
   455  		},
   456  		Error:   "",
   457  		LocalGB: 12,
   458  		AllInterfaces: map[string]introspection.BaseInterfaceType{
   459  			"eth1": {
   460  				IP:  "172.24.42.101",
   461  				MAC: "52:54:00:47:20:4d",
   462  				PXE: false,
   463  			},
   464  			"eth0": {
   465  				IP:  "172.24.42.100",
   466  				MAC: "52:54:00:4e:3d:30",
   467  				PXE: true,
   468  				LLDPProcessed: map[string]interface{}{
   469  					"switch_chassis_id":  "11:22:33:aa:bb:cc",
   470  					"switch_system_name": "sw01-dist-1b-b12",
   471  				},
   472  			},
   473  		},
   474  		RawLLDP: map[string][]introspection.LLDPTLVType{
   475  			"eth0": {
   476  				{
   477  					Type:  1,
   478  					Value: "04112233aabbcc",
   479  				},
   480  				{
   481  					Type:  5,
   482  					Value: "737730312d646973742d31622d623132",
   483  				},
   484  			},
   485  		},
   486  	}
   487  
   488  	IntrospectionExtraHardware = introspection.ExtraHardwareDataType{
   489  		CPU: introspection.ExtraHardwareDataSection{
   490  			"logical": map[string]interface{}{
   491  				"number": float64(16),
   492  			},
   493  			"physical": map[string]interface{}{
   494  				"clock": float64(2105032704),
   495  				"cores": float64(8),
   496  				"flags": "lm fpu fpu_exception wp vme de",
   497  			},
   498  		},
   499  		Disk: introspection.ExtraHardwareDataSection{
   500  			"sda": map[string]interface{}{
   501  				"rotational": float64(1),
   502  				"vendor":     "TEST",
   503  			},
   504  		},
   505  		Firmware: introspection.ExtraHardwareDataSection{
   506  			"bios": map[string]interface{}{
   507  				"date":   "01/01/1970",
   508  				"vendor": "test",
   509  			},
   510  		},
   511  		IPMI: introspection.ExtraHardwareDataSection{
   512  			"Fan1A RPM": map[string]interface{}{
   513  				"unit":  "RPM",
   514  				"value": float64(3120),
   515  			},
   516  			"Fan1B RPM": map[string]interface{}{
   517  				"unit":  "RPM",
   518  				"value": float64(2280),
   519  			},
   520  		},
   521  		Memory: introspection.ExtraHardwareDataSection{
   522  			"bank0": map[string]interface{}{
   523  				"clock":       1600000000.0,
   524  				"description": "DIMM DDR3 Synchronous Registered (Buffered) 1600 MHz (0.6 ns)",
   525  			},
   526  			"bank1": map[string]interface{}{
   527  				"clock":       1600000000.0,
   528  				"description": "DIMM DDR3 Synchronous Registered (Buffered) 1600 MHz (0.6 ns)",
   529  			},
   530  		},
   531  		Network: introspection.ExtraHardwareDataSection{
   532  			"em1": map[string]interface{}{
   533  				"Autonegotiate": "on",
   534  				"loopback":      "off [fixed]",
   535  			},
   536  			"p2p1": map[string]interface{}{
   537  				"Autonegotiate": "on",
   538  				"loopback":      "off [fixed]",
   539  			},
   540  		},
   541  		System: introspection.ExtraHardwareDataSection{
   542  			"ipmi": map[string]interface{}{
   543  				"channel": float64(1),
   544  			},
   545  			"kernel": map[string]interface{}{
   546  				"arch":    "x86_64",
   547  				"version": "3.10.0",
   548  			},
   549  			"motherboard": map[string]interface{}{
   550  				"vendor": "Test",
   551  			},
   552  			"product": map[string]interface{}{
   553  				"name":   "test",
   554  				"vendor": "Test",
   555  			},
   556  		},
   557  	}
   558  
   559  	IntrospectionNUMA = introspection.NUMATopology{
   560  		CPUs: []introspection.NUMACPU{
   561  			{
   562  				CPU:            6,
   563  				NUMANode:       1,
   564  				ThreadSiblings: []int{3, 27},
   565  			},
   566  			{
   567  				CPU:            10,
   568  				NUMANode:       0,
   569  				ThreadSiblings: []int{20, 44},
   570  			},
   571  		},
   572  		NICs: []introspection.NUMANIC{
   573  			{
   574  				Name:     "p2p1",
   575  				NUMANode: 0,
   576  			},
   577  			{
   578  				Name:     "p2p2",
   579  				NUMANode: 1,
   580  			},
   581  		},
   582  		RAM: []introspection.NUMARAM{
   583  			{
   584  				NUMANode: 0,
   585  				SizeKB:   99289532,
   586  			},
   587  			{
   588  				NUMANode: 1,
   589  				SizeKB:   100663296,
   590  			},
   591  		},
   592  	}
   593  )
   594  
   595  // HandleListIntrospectionsSuccessfully sets up the test server to respond to a server ListIntrospections request.
   596  func HandleListIntrospectionsSuccessfully(t *testing.T) {
   597  	th.Mux.HandleFunc("/introspection", func(w http.ResponseWriter, r *http.Request) {
   598  		th.TestMethod(t, r, "GET")
   599  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   600  		w.Header().Add("Content-Type", "application/json")
   601  		r.ParseForm()
   602  
   603  		marker := r.Form.Get("marker")
   604  
   605  		switch marker {
   606  		case "":
   607  			fmt.Fprintf(w, IntrospectionListBody)
   608  
   609  		case "c244557e-899f-46fa-a1ff-5b2c6718616b":
   610  			fmt.Fprintf(w, `{ "introspection": [] }`)
   611  
   612  		default:
   613  			t.Fatalf("/introspection invoked with unexpected marker=[%s]", marker)
   614  		}
   615  	})
   616  }
   617  
   618  // HandleGetIntrospectionStatusSuccessfully sets up the test server to respond to a GetIntrospectionStatus request.
   619  func HandleGetIntrospectionStatusSuccessfully(t *testing.T) {
   620  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b", func(w http.ResponseWriter, r *http.Request) {
   621  		th.TestMethod(t, r, "GET")
   622  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   623  		th.TestHeader(t, r, "Accept", "application/json")
   624  		fmt.Fprintf(w, IntrospectionStatus)
   625  	})
   626  }
   627  
   628  // HandleStartIntrospectionSuccessfully sets up the test server to respond to a StartIntrospection request.
   629  func HandleStartIntrospectionSuccessfully(t *testing.T) {
   630  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b", func(w http.ResponseWriter, r *http.Request) {
   631  		th.TestMethod(t, r, "POST")
   632  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   633  		w.WriteHeader(http.StatusAccepted)
   634  	})
   635  }
   636  
   637  // HandleAbortIntrospectionSuccessfully sets up the test server to respond to an AbortIntrospection request.
   638  func HandleAbortIntrospectionSuccessfully(t *testing.T) {
   639  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b/abort", func(w http.ResponseWriter, r *http.Request) {
   640  		th.TestMethod(t, r, "POST")
   641  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   642  		w.WriteHeader(http.StatusAccepted)
   643  	})
   644  }
   645  
   646  // HandleGetIntrospectionDataSuccessfully sets up the test server to respond to a GetIntrospectionData request.
   647  func HandleGetIntrospectionDataSuccessfully(t *testing.T) {
   648  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b/data", func(w http.ResponseWriter, r *http.Request) {
   649  		th.TestMethod(t, r, "GET")
   650  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   651  		th.TestHeader(t, r, "Accept", "application/json")
   652  
   653  		fmt.Fprintf(w, IntrospectionDataJSONSample)
   654  	})
   655  }
   656  
   657  // HandleReApplyIntrospectionSuccessfully sets up the test server to respond to a ReApplyIntrospection request.
   658  func HandleReApplyIntrospectionSuccessfully(t *testing.T) {
   659  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b/data/unprocessed", func(w http.ResponseWriter, r *http.Request) {
   660  		th.TestMethod(t, r, "POST")
   661  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   662  		w.WriteHeader(http.StatusAccepted)
   663  	})
   664  }