Exemple #1
0
/*
	Test count with an empty string.
*/
func TestToken_count_empty(t *testing.T) {
	cmap := token.Tokenise_count(" ", " ")
	fmt.Fprintf(os.Stderr, "count of empty string resulted in cmap of %d elements\n\n", len(cmap))

	for k, v := range cmap {
		fmt.Fprintf(os.Stderr, "(%s) == %d\n", k, v)
	}
	fmt.Fprintf(os.Stderr, "\n")
}
Exemple #2
0
/*
	Returns a list of openstack compute and network hosts. Hosts where OVS is likely
	running.
*/
func get_hosts(os_refs map[string]*ostack.Ostack) (s *string, err error) {
	var (
		ts   string  = ""
		list *string // list of host from the openstack world
	)

	s = nil
	err = nil
	sep := ""

	if os_refs == nil || len(os_refs) <= 0 {
		err = fmt.Errorf("no openstack creds in list to query")
		return
	}

	osif_sheep.Baa(2, "physical host query starts: %d sets of creds", len(os_refs))
	for k, ostk := range os_refs {
		bs_class := fmt.Sprintf("osif_gh_%s", k) // baa_some class for this project

		osif_sheep.Baa(2, "physical host query for %s", k)
		if k != "_ref_" {
			list, err = ostk.List_enabled_hosts(ostack.COMPUTE | ostack.NETWORK)
			osif_sheep.Baa(2, "physical host query for %s err is nil %v", k, err == nil)
			if err != nil {
				osif_sheep.Baa_some(bs_class, 100, 1, "WRN: error accessing host list: for %s: %s   [TGUOSI001]", ostk.To_str(), err)
				//ostk.Expire()					// force re-auth next go round
			} else {
				osif_sheep.Baa_some_reset(bs_class) // reset on good attempt so 1st failure after good is logged
				if *list != "" {
					ts += sep + *list
					sep = " "
					osif_sheep.Baa(2, "list of hosts was returned by %s  ", ostk.To_str())
				} else {
					osif_sheep.Baa(2, "WRN: list of hosts not returned by %s   [TGUOSI002]", ostk.To_str())
				}
			}
		}
	}

	cmap := token.Tokenise_count(ts, " ") // break the string, and then dedup the values
	ts = ""
	sep = ""
	for k, v := range cmap {
		if v > 0 {
			ts += sep + k
			sep = " "
		}
	}

	osif_sheep.Baa(2, "phys host query ends: %d hosts", len(cmap))
	s = &ts
	return
}
Exemple #3
0
/*
	Returns a list of openstack compute and network hosts. Hosts where OVS is likely
	running.

	WARNING: openstack may not send back host names with any consistency: some come
	with domain names and some without. Probably due to who configured the environment,
	but annoying, and problematic nonetheless. We will pass things along unchanged,
	but it's probalby wise for the user code to strip the domain if they think it
	best (might not be best for the agent manager).
*/
func get_hosts(os_refs map[string]*ostack.Ostack) (s *string, err error) {
	var (
		ts   string  = ""
		list *string // list of host from the openstack world
	)

	s = nil
	err = nil
	sep := ""

	if os_refs == nil || len(os_refs) <= 0 {
		err = fmt.Errorf("no openstack creds in list to query")
		return
	}

	if ostk := os_refs["admin"]; ostk != nil {
		k := "admin"
		list, err = ostk.List_enabled_hosts(ostack.COMPUTE | ostack.L3)
		osif_sheep.Baa(2, "physical host query for %s err is nil %v", k, err == nil)
		if err != nil {
			osif_sheep.Baa(1, "WRN: error accessing host list with creds: %s: %s   [TGUOSI001]", ostk.To_str(), err)
		} else {
			if *list != "" {
				ts += sep + *list
				sep = " "
				osif_sheep.Baa(2, "list of hosts was returned using creds: %s", ostk.To_str())
			} else {
				osif_sheep.Baa(2, "WRN: list of hosts not returned using creds: %s   [TGUOSI002]", ostk.To_str())
			}
		}
	} else {
		osif_sheep.Baa(1, "cannot get host list, chost list no admin project in credential list")
	}

	cmap := token.Tokenise_count(ts, " ") // break the string, and then dedup the values
	ts = ""
	sep = ""
	for k, v := range cmap {
		if v > 0 {
			ts += sep + k
			sep = " "
		}
	}

	osif_sheep.Baa(2, "phys host query ends: %d hosts", len(cmap))
	s = &ts
	return
}
Exemple #4
0
/*
	Test a case where we have more than 2k tokens in the buffer.
*/
func TestLarge_token_count(t *testing.T) {

	fmt.Fprintf(os.Stderr, "\n")

	str := ""
	sep := ""
	for i := 0; i < 4360; i++ { // build a long string of space separated tokens
		str += fmt.Sprintf("%s%d", sep, i%100) // 100 unique tokens
		sep = " "
	}

	cmap := token.Tokenise_count(str, " ")
	if len(cmap) != 100 {
		fmt.Fprintf(os.Stderr, "FAIL: large_token_count: expected 100 unique tokens, found %d\n", len(cmap))
		for k := range cmap { // key is the token
			fmt.Fprintf(os.Stderr, "%s\n", k)
		}
		t.Fail()
	} else {
		fmt.Fprintf(os.Stderr, "OK:   large_token_count: expected 100 unique tokens, found 100\n")
	}
}
Exemple #5
0
func TestToken_count(t *testing.T) {

	str := "now is the time for all good boys to come to the aid of their country and to see if boys like dogs in the country"
	cmap := token.Tokenise_count(str, " ")

	if cmap == nil {
		fmt.Fprintf(os.Stderr, "tokenise count failed to return a map\n")
		t.Fail()
	}

	for k, v := range cmap {
		fmt.Fprintf(os.Stderr, "%s == %d\n", k, v)
	}

	emap := make(map[string]int)
	emap["aid"] = 1
	emap["the"] = 3
	emap["for"] = 1
	emap["country"] = 2
	emap["boys"] = 2
	emap["to"] = 3

	fcount := 0
	for k, v := range emap {
		if v == cmap[k] {
			fmt.Fprintf(os.Stderr, "      spot check: %s is good\n", k)
		} else {
			fmt.Fprintf(os.Stderr, "FAIL: spot check: %s  fails: %d != %d\n", k, v, cmap[k])
			fcount++
		}
	}

	if fcount > 0 {
		fmt.Fprintf(os.Stderr, "spot check failed\n")
		t.Fail()
	}

	return
}