tests: Refactor add_metadata_server_ function

Modify this function to make it much simpler to understand.

Change-Id: Ibe6a78e110c462b73d205c69df95c104ce838a35