Posts valid and invalid schedules to the maintenance schedule endpoint.
| 155 | |
| 156 | // Posts valid and invalid schedules to the maintenance schedule endpoint. |
| 157 | TEST_F(MasterMaintenanceTest, UpdateSchedule) |
| 158 | { |
| 159 | // Set up a master. |
| 160 | Try<Owned<cluster::Master>> master = StartMaster(); |
| 161 | ASSERT_SOME(master); |
| 162 | |
| 163 | // Extra machine used in this test. |
| 164 | // It isn't filled in, so it's incorrect. |
| 165 | MachineID badMachine; |
| 166 | |
| 167 | // Post a valid schedule with one machine. |
| 168 | maintenance::Schedule schedule = createSchedule( |
| 169 | {createWindow({machine1}, unavailability)}); |
| 170 | |
| 171 | Future<Response> response = process::http::post( |
| 172 | master.get()->pid, |
| 173 | "maintenance/schedule", |
| 174 | headers, |
| 175 | stringify(JSON::protobuf(schedule))); |
| 176 | |
| 177 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response); |
| 178 | |
| 179 | // Get the maintenance schedule. |
| 180 | response = process::http::get( |
| 181 | master.get()->pid, |
| 182 | "maintenance/schedule", |
| 183 | None(), |
| 184 | createBasicAuthHeaders(DEFAULT_CREDENTIAL)); |
| 185 | |
| 186 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response); |
| 187 | |
| 188 | // Check that the schedule was saved. |
| 189 | Try<JSON::Object> masterSchedule_ = |
| 190 | JSON::parse<JSON::Object>(response->body); |
| 191 | |
| 192 | ASSERT_SOME(masterSchedule_); |
| 193 | Try<mesos::maintenance::Schedule> masterSchedule = |
| 194 | ::protobuf::parse<mesos::maintenance::Schedule>(masterSchedule_.get()); |
| 195 | |
| 196 | ASSERT_SOME(masterSchedule); |
| 197 | ASSERT_EQ(1, masterSchedule->windows().size()); |
| 198 | ASSERT_EQ(1, masterSchedule->windows(0).machine_ids().size()); |
| 199 | ASSERT_EQ( |
| 200 | "Machine1", |
| 201 | masterSchedule->windows(0).machine_ids(0).hostname()); |
| 202 | |
| 203 | // Try to replace with an invalid schedule with an empty window. |
| 204 | schedule = createSchedule( |
| 205 | {createWindow({}, unavailability)}); |
| 206 | |
| 207 | response = process::http::post( |
| 208 | master.get()->pid, |
| 209 | "maintenance/schedule", |
| 210 | headers, |
| 211 | stringify(JSON::protobuf(schedule))); |
| 212 | |
| 213 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response); |
| 214 |
nothing calls this directly
no test coverage detected